See the example below:
(click image to view)
Here is the description about the HTML code above:
- The enctype attribute of the form tag specifies which content type to use when submitting a form.
- "multipart/form-data" is used when a form requires binary data, like the contents of a file, to be uploaded.
- The type="file" attribute of the input tag specifies that the input should be processed as a file.
Script for Uploading File
The "upload_file.php" file above contains the code for uploading a file:
(click image to view)
The description about the code above:
- $_FILES["file"]["name"] - the name of the uploaded file.
- $_FILES["file"]["type"] - the type of the uploaded file.
- $_FILES["file"]["size"] - the size in bytes of the uploaded file.
- $_FILES["file"]["tmp_name"] - the name of the temporary copy of the file stored on the server.
- $_FILES["file"]["error"] - the error code resulting from the file upload.
Restrictions on Upload
In the script below, we can try to add some restrictions to the file upload by just uploading .gif or .jpeg files and the file size must be under 50 kb:
(click image to view)
Saving the Uploaded File
(click image to view)
(click image to view)
No comments:
Post a Comment