Cyrus Bitangcol
Share This
//PHP File Upload Tutorial

PHP File Upload Tutorial

PHP File Upload Tutorial

In this tutorial we’ll create a simple php file image upload.
In this simple image file upload we will add a verification for file extension and size, making it a secure way to upload file.
You can use this for uploading images, pdf, zip file, rar, and doc, just make sure that you change the necessary part in the script.


<form action=”” enctype=”multipart/form-data” method=”POST”>
<input name=”image” type=”file” />
<input type=”submit” />

Make sure to add “enctype=”multipart/form-data” to form and type=”file” for the input


We will use “isset($_FILES[”])” to make sure some file is selected. $_FILES[‘ ‘] is an array with the file information. we will set the file name, size and tmp tmp_name is the temporary location where the file is uploaded

$file_name = $_FILES[‘image’][‘name’];
$file_size =$_FILES[‘image’][‘size’];
$file_tmp =$_FILES[‘image’][‘tmp_name’];

for the verification

$expensions= array(“jpeg”,”jpg”,”png”);

On this tutorial we need to allow the image extensions. You can add the appropriate extensions that you need. This is not recommended upload script you can change and modify it for your security, this is just for a simple tutorial purpose only.

if($file_size > 2097152){
$errors[]=’File size must be excately 2 MB’;
echo “Success”;

For the full code download the file on

File password: “singlefileupload”

  • 0 Comment
Get in Touch