Uploading Files/Images Using PHP & MySQL (Video Tutorial)

Uploading files such as Images, videos and other text documents may easily be uploaded using $_FILES default array in PHP 5.0. If you want to just test uploading files in PHP & MySQL then I’m here to help you out regarding this via video tutorials. File is a kind of media which has different parts to be uploaded to the files’ server. I’ll soon create one more tutorial in which you’ll be learning how to upload the files to the MySQL database and then re-call wherever you need them in the pages.

upload file in PHP

You can upload any kind of media using PHP, but this tutorial is just the basic idea for uploading a single file to file server but not to the MySQL database. However, you may upload different files at the same time using the same method.

Before going to learn this, you may want to also know about: 

What we’ll need to do?

  • Create a file with the name “upload_image.php
  • Save the file and give the name & extension as “upload_image.php
  • Now copy and paste all below source code into that file and save that

<title>Uploading images</title>


<form action=”upload_image.php” method=”post” enctype=”multipart/form-data”>

Select Image:<input type=”file” name=”image”>
<input type=”submit” name=”upload” value=”Upload Now”>


$image_name = $_FILES[‘image’][‘name’];
$image_type = $_FILES[‘image’][‘type’];
$image_size = $_FILES[‘image’][‘size’];
$image_tmp_name= $_FILES[‘image’][‘tmp_name’];

echo “<script>alert(‘Please Select an Image’)</script>”;

echo “Image Uploaded Successfully Here is the image”;
echo “<img src=’photos/$image_name’>”;


In the above source code, everything looks just fine and simple except the enctype=”multipart/form-data” which is always added as an attribute to the <form> tag when dealing with media files. Without adding enctype= you can’t add files into the server..

The $_FILES array is always used to get the media files, and there are three information which are stored in the local variables, because the media files are not a single data file, they might have different data types.

The Following three parameters are necessary to be saved into local variables:

  • $image_name = $_FILES[‘image’][‘name’];
  • $image_type = $_FILES[‘image’][‘type’];
  • $image_size = $_FILES[‘image’][‘size’];

The name of the image is always saved into a local variable for using it later on, in the website, while the type of the image is used to set a file validation for the file. Because if we don’t set that then anyone can upload any type of file. And the “Size” is used to store the size of the image/file into a local variable, so we can then limit to a fixed size if we want.

The move_uploaded_file is a default function in PHP which moves the file into the files server folder which we mention in the line as you can see in the above source code.

This is very simple tutorial for uploading images using PHP, if you still need to know practically then you are welcome to watch below video tutorials for learning it more closely:

Uploading files to the server tutorial video #1

Uploading files to the server tutorial video #2

After watching the videos, I can just assume that you’ve learned what I tried to teach you in these videos 🙂 for more videos you can connect with this blog either via email or via Facebook.

Moreover, take few seconds to share this tutorial with all of your friends on social media and have a great time with PHP 😛

About Abdul Wali

Abdul Wali is a professional blogger, marketer and web developer working online for last 5 years, he's been deeply involved in PHP, Web Development, SEO and computer video tutorials in different languages i.e English, Urdu and Pashto. You can catch him on and add him on Facebook.

Check Also

web hosting

The Best Web Hosting Providers (Tutorial)

Web hosting is one of the important aspects for establishing a business or website online. If ...

  • Sharif SM

    Hai sir, your video was very usefull
    And now when I echo it It is not displaying the pic.. and the name of pic.. too

  • Sharif SM

    Hai sir Assalamualaikum,
    All your videos has been helpful to me and when I upload photo it works and when I need to update i.e change picture it is not updating sir !!



    echo "Insert Page";
    $image_name = $_FILES['image']['name'];
    $image_type = $_FILES['image']['type'];
    $image_size = $_FILES['image']['size'];
    $image_tmp_name= $_FILES['image']['tmp_name'];
    $target_path = move_uploaded_file($image_tmp_name,"photos/$image_name");


    $sql=”update users set userpic='”.$target_path.”‘ email='”.$b.”‘, pass='”.$c.”‘ where id=’$a'”;
    echo “alert(‘Updated Successfully’)”;