Return to Snippet

Revision: 16895
at August 18, 2009 16:05 by hasantayyar


Initial Code
<?php
/********************
*@file - path to file
*/
function force_download($file)
{
    if ((isset($file))&&(file_exists($file))) {
       header("Content-length: ".filesize($file));
       header('Content-Type: application/octet-stream');
       header('Content-Disposition: attachment; filename="' . $file . '"');
       readfile("$file");
    } else {
       echo "No file selected";
    }
}


?>

Initial URL


Initial Description


Initial Title
Force download a file

Initial Tags
php, download

Initial Language
PHP