Video tutorial: How to allow users upload files from a web page to server with PHP
In this post I will explain how to allow our visitors or site admin to upload files to our web server from a web page using html forms and php syntax.
Sometimes we may want to let our visitors to upload photos, docs or any other files to our server.
I will teach you to add file component to your forms in order to perform such tasks.
I will also show how to block harmful files and prevent them from being uploaded.
Here is the code I used in this lesson:
<form action=”admin_add_product_go.php” method=”post” name=”add” enctype=”multipart/form-data”>
Small picture:<br /><input type=”file” name=”file” id=”file” /><br />
Big picture:<br /><input type=”file” name=”file2″ id=”file2″ /><br />
</form>
//find out the id we just inserted
$id = mysql_insert_id();
//upload first file
if ((($_FILES["file"]["type"] == “image/gif”)
|| ($_FILES["file"]["type"] == “image/jpeg”)
|| ($_FILES["file"]["type"] == “image/pjpeg”))
&& ($_FILES["file"]["size"] < 200000))
move_uploaded_file($_FILES["file"]["tmp_name"],”prod/” . $id.”s.jpg”);
//upload second file
if ((($_FILES["file2"]["type"] == “image/gif”)
|| ($_FILES["file2"]["type"] == “image/jpeg”)
|| ($_FILES["file2"]["type"] == “image/pjpeg”))
&& ($_FILES["file2"]["size"] < 200000))
move_uploaded_file($_FILES["file2"]["tmp_name"],”prod/” . $id.”b.jpg”);
Related Posts
- How to create custom made 404 error file not found page on your website video tutorial
- Video tutorials: PHP Mail function – How to send emails from your web server or localhost
- Video PHP tutorials: Manage statistics ( stats ) using the SERVER object
- Video tutorial: How to create CSS button rollover effect menu web design tutorial
- Video Tutorial: how to use any custom made font on your website using facelift video tutorial







(5 votes, average: 4.60 out of 5)
Comments (1)
thank you very much your are the best #1
=)
Leave a reply