docs:programming:php:direct_file_download

Direct File Download

The goal is to provide users with a file download, directly in a php script rather than a hard link on a remote filesystem. This allows us to implement user authentication prior to any files being available.

FIXME All of this will likely work, but so far is untested

<?
$dir="/path/to/file/";
if (isset($_REQUEST["file"])) {
    $file=$dir.$_REQUEST["file"];
    header("Content-type: application/force-download");
    header("Content-Transfer-Encoding: Binary");
    header("Content-length: ".filesize($file));
    header("Content-disposition: attachment; filename=\"".basename($file)."\"");
    readfile("$file");
} else {
    echo "No file selected";
}
?> 
  • docs/programming/php/direct_file_download.txt
  • Last modified: 2008/08/03 00:25
  • by 127.0.0.1