Answer the question
In order to leave comments, you need to log in
How to properly issue files for download through php?
Good afternoon, there is a script that gives files for download to the user
$fname=$_GET['fname'];
$prgid=$_GET['prgid'];
$f=fopen($fdown, 'r');
header("HTTP/1.1 200 OK");
header("Connection: close");
header("Content-Type: application/octet-stream");
header("Accept-Ranges: bytes");
header("Content-Disposition: Attachment; filename=".$fname);
header("Content-Length: ".$fsize);
while (!feof($f)) {
if (connection_aborted()) {
fclose($f);
break;
}
echo fread($f, 10000);
sleep(1);
}
fclose($f);
Answer the question
In order to leave comments, you need to log in
Several methods are described in detail here:
habrahabr.ru/post/151795
In my opinion, it is better to use modules specially designed for this:
For nginx - X-Accel-Redirect
header('X-Accel-Redirect: ' . $file);
header('Content-Disposition: attachment; filename=' . basename($file));
header('X-SendFile: ' . $file);
header('Content-Disposition: attachment; filename=' . basename($file));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question