Tuesday, 8 October 2013

Php script for downloading files

In this article am going to explain you how to create PHP file downloader to download any files from web server to local machine. This application works mainly on the header of the PHP.
When you want to download any file you need to send the file name to this application, rest of the thing PHP will handle.

Set the file path
    //set the time out
    //path to the file
    //Call the download function with file path,file name and file type
    output_file($file_path, ''.$_GET['filename'].'', 'text/plain'); 

Now check the file for extensions and permission
    //File size
    $size = filesize($file);
    $name = rawurldecode($name);
    /* Figure out the MIME type */
    "pdf" => "application/pdf",
    "txt" => "text/plain",
    "html" => "text/html",
    "htm" => "text/html",
    "exe" => "application/octet-stream",
    "zip" => "application/zip",
    "doc" => "application/msword",
    "xls" => "application/vnd.ms-excel",
    "ppt" => "application/vnd.ms-powerpoint",
    "gif" => "image/gif",
    "png" => "image/png",
    "jpeg"=> "image/jpg",
    "jpg" => "image/jpg",
    "php" => "text/plain"

No comments:

Post a Comment