Uploading file is one of the most common feature which we normally use in our daily life, we do upload pictures on Facebook, Twitter and other websites. So today i will share a tutorial about how to upload file using PHP and save/store that file in your web server directory.
HTML Form
We will need a form with one input field with file type. The action tag of form should point to the URL of PHP script file which actually perform the uploading task. It is also important to add enctype="multipart/form-data" property in your form to upload file otherwise your file will not be uploaded.
PHP Script
As you can see above i tried to use the variable name as its function so that you can easily understand what i am doing, i just check that if file already exist it will print the error otherwise file will be uploaded.
This tutorial is only for the basic learning purpose, if you want to implement it on your website so it is better to use more validation before uploading file.
Validation such as file type (extension) or file size can also be check on the client side i also wrote tutorial Check File Size & Extension Before Uploading Using jQuery.
If you found this tutorial helpful so share it with your friends, developer groups and leave your comment.
No comments:
Post a Comment