note 114483 added to function.readfile
| From: | Brian | Date: | Tue, 25 Feb 2014 13:01:11 +0000 |
| Subject: | note 114483 added to function.readfile | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-198709@lists.php.net to get a copy of this message | ||
If you are looking for an algorithm that will allow you to download (force download) a big file, may
this one will help you.
$filename = "file.csv";
$filepath = "/path/to/file/" . $filename;
// Close sessions to prevent user from waiting until
// download will finish (uncomment if needed)
//session_write_close();
set_time_limit(0);
ignore_user_abort(false);
ini_set('output_buffering', 0);
ini_set('zlib.output_compression', 0);
$chunk = 10 * 1024 * 1024; // bytes per chunk (10 MB)
$fh = fopen($filepath, "rb");
if ($fh === false) {
echo "Unable open file";
}
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="' . $filename .
'"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($filepath));
// Repeat reading until EOF
while (!feof($fh)) {
echo fread($handle, $chunk);
ob_flush(); // flush output
flush();
}
exit;
----
Server IP: 72.55.140.6
Probable Submitter: 78.45.76.35
----
Manual Page -- http://php.net/manual/en/function.readfile.php
Edit -- https://master.php.net/note/edit/114483
Del: integrated -- https://master.php.net/note/delete/114483/integrated
Del: useless -- https://master.php.net/note/delete/114483/useless
Del: bad code -- https://master.php.net/note/delete/114483/bad+code
Del: spam -- https://master.php.net/note/delete/114483/spam
Del: non-english -- https://master.php.net/note/delete/114483/non-english
Del: in docs -- https://master.php.net/note/delete/114483/in+docs
Del: other reasons-- https://master.php.net/note/delete/114483
Reject -- https://master.php.net/note/reject/114483
Search -- https://master.php.net/manage/user-notes.php