How to Upload Files using PHP…..

Posted by & filed under PHP.

Here is simple coding in PHP to upload your files to server. Just follow this simple steps to upload your files. You can upload your all format of files, photos and pictures from local computer to server using this following php scripts.

Step 1: Create an HTML form to select file to upload.

html form to upload file- php file upload

Html Form To Upload File

this is above html form code

<form action="upload.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>

In the form you need specify some important attributes to process your file

action=”upload.php’ – this php file process the uploaded file.

method=’POST’ – you passing your files using post method.

enctype=”multipart/formdata” – this content type used when you sending files.

Step 2: Create upload.php to process your files.

<?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 "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 "The file ".basename( $_FILES['uploaded']['name']). " has been uploaded";
 }
 else {
 echo "Sorry, there was a problem uploading your file.";
 }

	 }

	}

?>

where

mkdir(‘test’)- is function which creates directory named ‘test’ during run time.

$_FILES[‘uploaded’][‘tmp_name’] – which outputs temporary address with filename

move_uploaded_file() – function which moves temporary file into targeted folder on the server.

 

 .

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!