Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

File size is not visible in php download readfile

I used below code to force browser start download:

//send file
$fileName = basename($fullPath);
$length = filesize($fullPath);

header('Content-Type: application/octet-stream');
header("Content-Transfer-Encoding: Binary");
header('Content-length: ' .  $length);
header("Content-disposition: attachment; filename=$fileName");

readfile($fullPath);

exit;

Everything's ok except total file size is not showing in browser (Firefox & Chrome). I searched the community and also test below code in htaccess with no success :

SetEnv no-gzip dont-vary

SetEnvIfNoCase Request_URI ...

My web server is Apache and PHP is in version 8.3

Is there any other option to check?

like image 308
faeqeh fassihi Avatar asked Sep 18 '25 11:09

faeqeh fassihi


1 Answers

Recently I had the same problem! Suggest that add this header too rather than htaccess solution

//to show file-size in browser
header("Content-Encoding: none");
like image 126
Kranchi Avatar answered Sep 21 '25 02:09

Kranchi