This article mainly introduces the PHP readfile download large file failure solution, involving PHP for large file segmentation and block-by-piece download operation implementation skills, the need for friends can refer to the next
This article describes a workaround for PHP readfile to download large file failures. Share to everyone for your reference, as follows:
Large file has more than 200 m, download only 200K is prompted to download the completion, and do not error.
The reason is that there is a limit in PHP, you need to download by block, that is, the large files are sliced and downloaded block by piece .
if (file_exists ($file)) {if (false!== ($handler = fopen ($file, ' R '))) {Header (' Content-description:file Transfer '); Header (' Content-type:application/octet-stream '); Header (' content-disposition:attachment; Filename= '. basename ($file)); Header (' content-transfer-encoding:chunked '); Changed to chunked header (' expires:0 '); Header (' Cache-control:must-revalidate, post-check=0, pre-check=0 '); Header (' Pragma:public '); Header (' Content-length: '. FileSize ($file)); Remove//send the content in chunks while (false!== ($chunk = fread ($handler, 4096)) {echo $chunk; }} exit; echo "