My VIDEO courses:

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

  1. How to create custom made 404 error file not found page on your website video tutorial
  2. Video tutorials: PHP Mail function – How to send emails from your web server or localhost
  3. Video PHP tutorials: Manage statistics ( stats ) using the SERVER object
  4. Video tutorial: How to create CSS button rollover effect menu web design tutorial
  5. Video Tutorial: how to use any custom made font on your website using facelift video tutorial
1 Star2 Stars3 Stars4 Stars5 Stars (5 votes, average: 4.60 out of 5)
Loading ... Loading ...

Filed Under: PHP and MySql

Tags: , , , , , , ,

Comments (1)

leb dev June 4th, 2010 at 00:29    

thank you very much your are the best #1
=)

Leave a reply

Name *

Mail *

Website

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word