Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Attaching a file on a page

Status
Not open for further replies.

mathieustar

IS-IT--Management
Jul 12, 2005
5
GB
Hello,

In many sites we can see a page with a forms, just text boxes to fulfill. Often, there is also a feature to be able to Browse through your Hard Drive and to attach a file to the form. (like your picture for exemple)

I would like to do this.

I already have the form and the database behind. But I have no idea how to make the user able to attach on of his file.

Can someone explain to me the procedure to follow?

Thanks for your assistance
 
That'll depend on your code platform...

ASP 3.0?
ASP.Net?
A.N.Other?

...and is probably best addressed on the appropriate forum for that platform.

However, it really isn't that difficult. All you need is an HTML input control of type="file";
Code:
<input id="filMyFile" type="file" runat="server" name="filMyFile">
and to know how to validate and process the upload server side, which is where you need to look at exactly what language you're programming in.

Rhys
"There are some oddities in the perspective with which we see the world. The fact that we live at the bottom of a deep gravity well, on the surface of a gas-covered planet going around a nuclear fireball 90 million miles away and think this to be normal is obviously some indication of how skewed our perspective tends to be"
DOUGLAS AD
 
It's pretty easy to do in PHP. Do you want to physically upload the file to a server and store it there or have it emailed somewhere or what?

Whatever language/method you use be aware that uploading of any file to your server is a security risk.

Make sure you take adequate steps to ensure the file is safe before allowing it anywhere near an executable directory.
Once you've done that, take even more precautions!

Foamcow Heavy Industries - Web design and ranting
Target Marketing Communications - Advertising, Direct Marketing and Public Relations
I wonder what possesses people to make those animated gifs. Do you just get up in the morning and think, "You know what web design r
 
Foamcow can you tell me how to do that in PHP please?

I just want the user to be able to put a file in the directory. Then all the other users could use it.

The security issues will be looked at later, but this is the first thing I'd like to be able to do.

Thank you
 
When I said it was easy, that's "comparatively easy"... hehe
While it's not beginners stuff, it's not too hard and there are plenty of tutorials out there.

When an file is submitted via a form various bits of info about the file are stored in the $_FILES global array.
You will need to get the temporary name that PHP has given the file by checking that array.
You can then move the file using the move_uploaded_file function, rename it etc.
Most importantly you MUST thoroughly check it to confirm it's nothing dangerous. Don't just check the file extension. Look for other methods to confirm what the file actually is.


The security issues should be looked at before you start. It's easier that way.

Uploaded files should not be stored in a user executable directory. Ideally they should be outside the web root.

May I suggest a google for "PHP upload script" and a visit to the Tek-Tips PHP forum (forum:434)

Also check the PHP online manual and look up the $_FILES global and associated functions.

Foamcow Heavy Industries - Web design and ranting
Target Marketing Communications - Advertising, Direct Marketing and Public Relations
I wonder what possesses people to make those animated gifs. Do you just get up in the morning and think, "You know what web design r
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top