PHP Download Script

PHP File Download Script

Using a PHP Download Script can be a convenient method for which to keep track of uploads and downloads on a website. The script could be used in a method for which the administrator can login to the backend and set files for downloading. The files could be any extension from jpeg to mp3 to txt. One free php downkoad script can be found here. The php file download script demo can be seen here.

File upload and download scripts can be extremely useful for people who surf the web and want to store jquery plugins, javascripts and other code formats like css. File management will make code reusability much simpler and faster.

The heart of PHP upload and download scripts can be easy to make. The upload script will need a form an input box designed for file uploads while the download script will need to force downloads for various file types. 

PHP File Upload Code:

<form enctype="multipart/form-data" action="<? echo $_SERVER['PHP_SELF']; ?>" method="post">

    <input type="hidden" name="MAX_FILE_SIZE" value="1000000">
    <input type="hidden" name="myhid" value ="hi">
    <style type="text/css">

PHP File Download Code:

$filepath = $_SERVER['DOCUMENT_ROOT']."/uploads/".$myfilename;
if (file_exists($filepath)) {
//download application
   header("Content-Type: application/force-download");
   //the filename will be given below
   header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename='.basename($myfilename));
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0');
    header('Cache-Control: must-revalidate');
    header('Pragma: public');
//open file in binary mode  
$my_file = fopen($filepath, 'rb');
//output data
//close file