mirror of
https://github.com/prasathmani/tinyfilemanager
synced 2024-06-08 00:42:19 +02:00
file streaming using fpassthru()
Signed-off-by: Manish4586 <manish.n.manish45@gmail.com>
This commit is contained in:
parent
7c2d079ad4
commit
03dc482178
|
@ -3170,15 +3170,15 @@ function fm_get_file_mimes($extension)
|
|||
* instead of download prompt
|
||||
* https://stackoverflow.com/a/13821992/1164642
|
||||
*/
|
||||
function fm_download_file($fileLocation, $fileName, $chunkSize = 1024)
|
||||
{
|
||||
if (connection_status() != 0)
|
||||
return (false);
|
||||
$extension = pathinfo($fileName, PATHINFO_EXTENSION);
|
||||
function fm_download_file($fileLocation, $fileName, $chunkSize = 65536) {
|
||||
if (connection_status() != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$extension = pathinfo($fileName, PATHINFO_EXTENSION);
|
||||
$contentType = fm_get_file_mimes($extension);
|
||||
|
||||
if(is_array($contentType)) {
|
||||
if (is_array($contentType)) {
|
||||
$contentType = implode(' ', $contentType);
|
||||
}
|
||||
|
||||
|
@ -3206,18 +3206,8 @@ function fm_download_file($fileLocation, $fileName, $chunkSize = 1024)
|
|||
header('Pragma: public');
|
||||
header("Content-Transfer-Encoding: binary");
|
||||
header("Content-Type: $contentType");
|
||||
|
||||
$contentDisposition = 'attachment';
|
||||
|
||||
if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")) {
|
||||
$fileName = preg_replace('/\./', '%2e', $fileName, substr_count($fileName, '.') - 1);
|
||||
header("Content-Disposition: $contentDisposition;filename=\"$fileName\"");
|
||||
} else {
|
||||
header("Content-Disposition: $contentDisposition;filename=\"$fileName\"");
|
||||
}
|
||||
|
||||
header("Content-Disposition: attachment;filename=\"$fileName\"");
|
||||
header("Accept-Ranges: bytes");
|
||||
$range = 0;
|
||||
|
||||
if (isset($_SERVER['HTTP_RANGE'])) {
|
||||
list($a, $range) = explode("=", $_SERVER['HTTP_RANGE']);
|
||||
|
@ -3233,11 +3223,8 @@ function fm_download_file($fileLocation, $fileName, $chunkSize = 1024)
|
|||
header("Content-Length: " . $size);
|
||||
}
|
||||
|
||||
while (!feof($fp) && !connection_aborted() && ($chunk = fread($fp, $chunkSize)) !== false) {
|
||||
echo $chunk;
|
||||
ob_flush();
|
||||
flush();
|
||||
}
|
||||
// Stream the file content using fpassthru
|
||||
fpassthru($fp);
|
||||
|
||||
fclose($fp);
|
||||
|
||||
|
|
Loading…
Reference in a new issue