Sending correct file size with PHP download script

后端 未结 3 1096
长发绾君心
长发绾君心 2020-12-01 13:18

I created a file download script in PHP, it works, but web browsers report the file as \"Unknown Length\". My code is as follows:

function downloadFile($fil         


        
3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-01 13:58

    I had this same problem, and I fixed it by sending the Content-Length header before the Content-Disposition.

    header('Content-Type: video/mp4');
    header("Content-Transfer-Encoding: Binary"); 
    header("Content-Length: ".filesize($file_url));
    header("Content-disposition: attachment; filename=\"" . basename($file_url) . "\""); 
    readfile($file_url);
    

提交回复
热议问题