kingofkolt schrieb:
im trying to let a user download a file from my website, for example a
picture. i dont want the user to have to right-click and do save-as, but
instead i want a window to popup (the window with "Save File","Open
File","More Info",etc) so that the user can download it easily. i have a
feeling this has something to do with headers, but i have no idea what the
correct headers are.
/**
* Send a download
*
* Netscape (at least V7) (an perhaps other browsers too) adds
* a ".php" to the filename of the downloaded file. Mozilla does
* not show this behaviour. Solution (if applicable) is to use
* a link like
*
* <a href="download.php/?datei='.$file.'">
*
* The additional / does the trick.
*
*
* Other solution: use a script with no .php extension, but one
* with no ending at all. You need a special directory with a
* ".htaccess" including the line
*
* DefaultType: application/php;
*
* @param string $filename only the filename
* @param string $path path to directory of file
*/
function send_download($filename='',$path='')
{
$fullname=$path.$filename;
/*
* Headers
*/
header("Content-Type: application/octet-stream;");
header('Content-Disposition: attachment;filename='.$filename.';');
header('Content-Transfer-Encoding: binary;');
header('Content-Length: '.filesize($fullname).';');
$f=fopen($fullname,'rb');
fpassthru($f);
fclose($f);
}
I recommend using this with relatively small files (<50 MB) only.
Apache on Windows shows the behaviour of allocating RAM for the
whole size of the file, no matter what tricks you try to use in
order to prevent this (buffer-flushing during send etc).
AllOlli