This link has been bookmarked by 26 people . It was first bookmarked on 08 Apr 2006, by david.
-
Lost Coreenctype="multipart/form-data"
-
-
PHP - File Upload
A very useful aspect of PHP is its ability to manage file uploads to your server. Allowing users to upload a file to your server opens a whole can of worms, so please be careful when enabling file uploads.
PHP - File Upload: HTML Form
Before you can use PHP to manage your uploads, you must first build an HTML form that lets users select a file to upload. See our HTML Form lesson for a more in-depth look at forms.
HTML Code:
Choose a file to upload:
Here is a brief description of the important parts of the above code:
* enctype="multipart/form-data" - Necessary for our to-be-created PHP file to function properly.
* action="uploader.php" - The name of our PHP page that will be created, shortly.
* method="POST" - Informs the browser that we want to send information to the server using POST.
* input type="hidden" name="MA... - Sets the maximum allowable file size, in bytes, that can be uploaded. This safety mechanism is easily bypassed and we will show a solid backup solution in PHP. We have set the max file size to 100KB in this example.
* input name="uploadedfile" - uploadedfile is how we will access the file in our PHP script.
Save that form code into a file and call it upload.html. If you view it in a browser it should look like this:
Display:
Choose a file to upload:
After the user clicks submit, the data will be posted to the server and the user will be redirected to uploader.php. This PHP file is going to process the form data and do all the work.
PHP - File Upload: What's the PHP Going to Do?
Now that we have the right HTML form we can begin to code the PHP script that is going to handle our uploads. Typically, the PHP file should make a key decision with all uploads: keep the file or throw it away. A file might be thrown away from many reasons, including:
* The file is too large and you do not want to have it on your server.
* You wanted the person to upload a pict
-
-
Andy StandfieldPHP Tutorial - File Upload
Would you like to comment?
Join Diigo for a free account, or sign in if you are already a member.