readfile() reads data into a file starting from the position pointed by the file pointer, and supports synchronous and asynchronous operations, so this article will share with you how to set the PHP file size with the readfile() function. I hope it can help. to everyone.
Use the compressed package generated by PHP ZipArchive. Small compressed packages can be downloaded. Today I encountered a 404 error when it was over 150M. The first thing that came to mind was that the file size exceeded the default setting of PHP. The modification method is: Two:
php.ini: memory_limit
memory_limit sets the memory limit. If you use readfile() to read the file, it will be related to this. Modify this directly. After saving the value, restart php-fpm.
memory_limit = 128M
Finally remember: service php-fpm restart
ini_set
PHP ini_set is used to set php. The value of ini takes effect when the function is executed, so we can directly use it to modify the memory execution size. If some friends use virtual space, this function is a savior.
ini_set('memory_limit', '512M');
Full 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);
Related recommendations:
10 recommended articles about php readfile() function
The above is the detailed content of The readfile() function sets the php file size method. For more information, please follow other related articles on the PHP Chinese website!