php readfile() modification of file upload size case

墨辰丷
Release: 2023-03-26 17:00:01
Original
1483 people have browsed it

If the file upload is too large, an error will occur. This article mainly introduces php readfile() to modify the file upload size setting. If you are interested, you can learn about

The compressed package generated using PHP ZipArchive, small You can download the compressed package. 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. There are two ways to modify it:

php.ini :memory_limit

memory_limit sets the memory limit. If you use readfile() to read a file, it will be related to this. Just modify this value and save it, then restart php-fpm.

php Download file size setting PHP

memory_limit = 128M
Copy after login

Finally remember: service php-fpm restart

ini_set

PHP ini_set is used to set the value of php.ini, which takes effect when the function is executed. Then we can directly use it to modify the memory execution size. Some friends use this function if it is a virtual space. It's a savior.

PHP Set php.ini value PHP

ini_set('memory_limit', '512M');
Copy after login

Full example:

PHP

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);
Copy after login

Related recommendations:

readfile() function method to set the php file size

How to use the readfile() function in php to modify the file upload size setting. Detailed explanation

How to use phpreadfile() function to set the file size example

The above is the detailed content of php readfile() modification of file upload size case. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template