php file upload script

Posted by & filed under PHP.

Using following script we can upload files, photos, pictures, pdf files, images and etc… from your local computer to remote server. I explained all the $_FILES super global variables properties with example.

here is script with html form design

<form action="mkdir.php" method="post" enctype="multipart/form-data">

<table border="0" align="center" bgcolor="#353535" cellpadding="3">
  <tr>

   <td bgcolor="#FFFFFF" colspan="2" align="center">
    <p align="center" style="font-style:italic; font-weight:bold">HTML Form to Upload File</p>
    </td>
  </tr>o

  <tr>
    <td bgcolor="#FFFFFF" width="50%">Select File to Upload</td>
    <td bgcolor="#FFFFFF" width="50%">
    <input type="file" name="uploaded"/>

    </td>
  </tr>
  <tr>

   <td bgcolor="#FFFFFF" colspan="2" align="center">
    <input type="submit" name="submit" value="submit"/>
    </td>
  </tr>

</table>

</form>
<?php

if(isset($_POST['submit'])){

if(!is_dir('test')){

	 mkdir('test');
	$target='test/'.basename($_FILES['uploaded']['name']);
	if(move_uploaded_file($_FILES['uploaded']['tmp_name'],$target)){

		 echo " IF The file ".basename( $_FILES['uploaded']['name']). " has been uploaded";
 }
 else {
 echo "Sorry, there was a problem uploading your file.";
 }
}
 else {

	 $target='test/'.basename($_FILES['uploaded']['name']);
	if(move_uploaded_file($_FILES['uploaded']['tmp_name'],$target)){

		 echo " Else The file ".basename( $_FILES['uploaded']['name']). " has been uploaded".'<br>';

		 echo $_FILES['uploaded']['tmp_name'].'<br>';
		 echo $_FILES['uploaded']['type'].'<br>';
		 echo $_FILES['uploaded']['size'].'<br>';

 }
 else {
 echo "Sorry, there was a problem uploading your file.";
 }

	 }

	}

?>

 

where i am uploading image (thumbnail.jpg) to server

$_FILES[‘uploaded’][‘tmp_name’]  – which outputs temporary file address (C:\xampp\tmp\php569.tmp) , as well  php assign temporary name to the image (thumbnail.jpg) to php569.tmp. when you uploading files from local computer to server, php temporary stores that files in your computer local hard drive (C:\xampp\tmp\php569.tmp).
$_FILES[‘uploaded’][‘type’]  – which outputs the property of file you uploaded (image/jpeg)
$_FILES[‘uploaded’][‘size’]   – which outputs the size of the files you uploaded (7293 bytes)

$_FILES[‘uploaded’][‘name’]   – which outputs the name of the files you uploaded (thumbnail.jpg)

php file upload-photos-pictures-images-pdf files-upload

php file upload

.

Download Premium Only Scripts & 80+ Demo scripts Instantly at just 1.95 USD per month + 10% discount to all Exclusive Scripts

If you want any of my script need to be customized according to your business requirement,

Please feel free to contact me [at] muni2explore[at]gmail.com

Note: But it will be charged based on your customization requirement

Get Updates, Scripts & Other Useful Resources to your Email

Join 10,000+ Happy Subscribers on feedburner. Click to Subscribe (We don't send spam)
Every Email Subsciber could have access to download 100+ demo scripts & all future scripts.

Get Instant Script Download Access!