PHP Force Download Causing 0 Byte Files

后端 未结 8 1127
清歌不尽
清歌不尽 2020-12-10 16:11

I\'m trying to force download files from my web server using PHP. I\'m not a pro in PHP but I just can\'t seem to get around the problem of files downloading in 0 bytes in s

8条回答
  •  时光取名叫无心
    2020-12-10 17:07

    You need to specify the Content-Length header:

    header("Content-Length: " . filesize($filename));
    

    Also, you shouldn't send a Content-Transfer-Encoding header. Both of the HTTP/1.0 and HTTP/1.1 specs state that "HTTP does not use the Content-Transfer-Encoding (CTE) field of RFC 1521".

提交回复
热议问题