the simpliest upload/download

index.html

<form action="upload.php" method="POST" enctype="multipart/form-data">
    <input type="file" name="image" />
    <input type="submit"/>
</form>

<a href='download.php?file=yourfilename.here'>Download</a>

upload.php

<?php
/*
* 	   Simple file Upload system with PHP.
* 	   Created By Tech Stream
* 	   Original Source at http://techstream.org/Web-Development/PHP/Single-File-Upload-With-PHP
*      This program is free software; you can redistribute it and/or modify
*      it under the terms of the GNU General Public License as published by
*      the Free Software Foundation; either version 2 of the License, or
*      (at your option) any later version.
*      
*      This program is distributed in the hope that it will be useful,
*      but WITHOUT ANY WARRANTY; without even the implied warranty of
*      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*      GNU General Public License for more details.
*     
*/
	if(isset($_FILES&#91;'image'&#93;)){
		$errors= array();
		$file_name = $_FILES&#91;'image'&#93;&#91;'name'&#93;;
		$file_size =$_FILES&#91;'image'&#93;&#91;'size'&#93;;
		$file_tmp =$_FILES&#91;'image'&#93;&#91;'tmp_name'&#93;;
		$file_type=$_FILES&#91;'image'&#93;&#91;'type'&#93;;   
		$file_ext=strtolower(end(explode('.',$_FILES&#91;'image'&#93;&#91;'name'&#93;)));
		
		$expensions= array("jpeg","jpg","png"); 		
		if(in_array($file_ext,$expensions)=== false){
			$errors&#91;&#93;="extension not allowed, please choose a JPEG or PNG file.";
		}
		if($file_size > 2097152){
		$errors[]='File size must be excately 2 MB';
		}				
		if(empty($errors)==true){
			$t = getcwd();
			move_uploaded_file($file_tmp,$t."/images/".$file_name);
			echo "Success"."<BR/>"; 
			echo "File Name :".$_FILES['image']['name']."<BR/>"; 
			echo "File Size :".$_FILES['image']['size']."<BR/>"; 
			echo "File Type :".$_FILES['image']['type']."<BR/>"; 
			//echo "<img src=\"$path\" width=\"150\" height=\"150\">";
		}else{
			print_r($errors);
		}
	}
?>

download.php

<?php

$file = basename($_GET&#91;'file'&#93;);
$t = getcwd();

$file = $t . '/images/'.$file;

if(!$file){ // file does not exist
    die('file not found');
} else {
    header("Cache-Control: public");
    header("Content-Description: File Transfer");
    header("Content-Disposition: attachment; filename=".$_GET&#91;'file'&#93;);
    header("Content-Type: application/zip");
    header("Content-Transfer-Encoding: binary");

    // read the file from disk
    readfile($file);
}

?>

the directory structure is :
index.html
\images\ <--here uploads_the dir_must_exists - set CHMOD=700 upload.php download.php ------------------- easier with : http://hayageek.com/docs/jquery-upload-file.php || https://github.com/hayageek/jquery-upload-file

By: |02/10/2014|