This article through the example code to explain PHP using the ReadFile () function to set the size of the file, the need for a friend to refer to it
Using PHP ziparchive generated compression package, small compressed package can be downloaded, today encountered more than 150M reported 404 error, the first thought is that the file size exceeds the PHP default settings, modified method has two:
Php.ini:memory_limit
Memory_limit is to set the memory limit, if the use of ReadFile () read the file will be related to this, directly modify this value after saving restart PHP-FPM can be.
Memory_limit = 128M
Last remember: Service php-fpm restart
Ini_set
PHP Ini_set is used to set the value of php.ini, when the function is executed, we directly used to modify the memory execution size, some friends use virtual space, this function is the Savior.
Ini_set (' Memory_limit ', ' 512M ');
A complete example:
Set_time_limit (0); Ini_set (' Memory_limit ', ' 512M '); Header ("Cache-control:public"); Header ("Content-description: File Transfer "), header (' content-disposition:attachment; Filename= '. basename ($zipfile)); Header (" Content-type: Application/zip "), Header (" Content-transfer-encoding:binary "), Header (' Content-length: '. FileSize ($zipfile)); ob_ Clean (); flush (); @readfile ($zipfile); unlink ($zipfile);