PHP image upload example – PHP uploader

In this php tutorial i want to explain how to make a basic php image upload with example code for beginner level and here not used any validation during upload. This php file upload script will tell you how to upload image in php,pictures upload php,photos to server using PHP script with a clear understanding. We will learn with validation which is actually used in our next tutorial. I create a lot of websites that allow administrators to image upload in php, picture upload php, photo upload php, images upload to their own website. I thought I’d share how easy it is to handle basic image upload in PHP or PHP image upload script.

We need two .php files and one upload folder where file uploaded and store.
index.php (Here used for the image upload php multipart form)
doupload.php (Used for action page of the above form and store image in upload folder)
One upload folder (Here upload folder name is upload)

This blog Post concerns about Image uploading in php functionality.

Learn PHP image upload step by step

create index.php for the form upload image php

<html>
<head>
</head>
<body>
<table width="500" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form action="doupload.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td><strong>Single File Upload by click4knowledge.com</strong></td>
</tr>
<tr>
<td>Select file
<input name="ufile" type="file" id="ufile" size="50" /></td>
</tr>
<tr>
<td align="center"><input type="submit" name="Submit" value="Upload" /></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
</body>
</html>

doupload.php

<?php
//first you have to set where you want to store files
//in this image upload script we keep file in folder upload
//$_FILES['ufile']['name']; = upload file name
//for example upload file name click4knowledge.gif . $path will be upload/click4knowledge.gif

$path= "upload/".$_FILES['ufile']['name'];
if($_FILES['ufile']['name'] != "")
{
if(copy($_FILES['ufile']['tmp_name'], $path))
{
echo "Successful<BR/>";
// print uploaded data after successful upload
echo "File Name :".$_FILES['ufile']['name']."<BR/>";
echo "File Size :".$_FILES['ufile']['size']."<BR/>";
echo "File Type :".$_FILES['ufile']['type']."<BR/>";
echo "<img src=\"$path\" width=\"150\" height=\"150\">";
}
else
{
echo "Error";
}
}
?>

After successful image upload you can check in the upload folder and you will get your uploaded image. So hope this file and image uploader tutorial and demo example code will be helpful for others.

Thanks for watching PHP image upload tutorial. You can try it yourself. Also you can use this script as a file upload script in php. I will share some useful script in PHP as well as some tips and tricks in PHP programming in our upcoming post. Viewers can subscribe our newsletter to get all the updates about web programming. If you like our post please share it. Reach our other tutorial here.
Support
Regarding any query about php image uploader, image uploader in php, image upload code in php, file or image uploader feel free to contact us via comment. We will love to help you.

13 responses to “PHP image upload example – PHP uploader”

  1. Guest says:

    I think the article is very helpful for us,it has solved our problem,thanks!

  2. Guest says:

    HI,
    This article is so helpful for me,i like it,thanks a lot!

  3. Anonymous says:

    My friend
    This post is very helpful for me,i like it very much,thank you!

  4. Temeka Ruffini says:

    very nice post, i certainly love this website, keep on it

  5. sanso says:

    I have a problem to upload image. i got an error message
    “JPG Warning: copy(): Filename cannot be empty in /home/click4/public_html/demos.click4knowledge.com/singleupload/index.php on line 66” The image i was trying to upload its 4Mb file and JPG format from sony DSC-WX200 camera please help me.

    • Hi Sanso,
      First of all thanks for trying our demo. Just checked your error message and it’s generate due to we are fix max upload size 1 MB. Please try with lower size image. Also if you have to work with large image then just set max upload size up to 4mb in your php.ini configuration. Thanks.

  6. Patrice Tsang says:

    How do I code in HTML file? Do I need HTML file? Just 2 php files that would work. Thanks.

  7. Arash Irani says:

    Hi, This is good, but it can be extend with some more feature!

  8. Rajesh says:

    Very helpful for me. Simple explanation.

Leave a Reply

Your email address will not be published. Required fields are marked *