Strange problem downloading large files

I am having a strange problem loading large files in PHP.

In php.ini max_execution_time set to 30, post_max_size set to 32M, upload_max_filesize set to 32M. When I tried to download a 40.2 MB file, it does not show any errors. The variable $_FILES is set to array(0) { } and $_FILES['userfile'] shows NULL .

If the file size is larger than the value specified in php.ini, it should return an error message

UPLOAD_ERR_INI_SIZE, value: 1; The downloaded file exceeds the upload_max_filesize directive in php.ini.

But it also does not show any errors (since $_FILES is an empty array). I do not know why this is happening.

When I modify php.ini and set post_max_size, it is set to 64M, upload_max_filesize set to 64M, then it works fine. So I decided to use the following code instead of modifying the php.ini file.

 ini_set('upload_max_filesize', '64M'); ini_set('post_max_size', '64M'); ini_set('max_execution_time', 300); 

I even tried increasing max_execution_time . However, I have the same problem. ini_set() does not work here.

+6
php file-upload
source share
4 answers

In order for a 40 MB file download to fail with an upload error, you need to increase the value of post_max_size, if you exceed the value of this variable, you will get an empty $ _FILES array. See manual

If the mail data size is larger than post_max_size, $ _POST and Superframes $ _FILES are empty.

In addition, ini_set () does not work there because the two variables you are trying to change are PHP_INI_PERDIR and therefore must be changed in php.ini or in .htaccess or httpd.conf. You should try a 40MB file, for example, these settings in .htaccess

 php_value upload_max_filesize 32M php_value post_max_size 64M php_value max_execution_time 300 
+19
source share

There is one more parameter that you may need, Apache LimitRequestBody .

If the file exceeds this, the download may be blocked before it even reaches PHP.

Apache Documentation

+1
source share

ini_set () does not work here.

The values ​​you are trying to change with ini_set() , except for max_execution_time , cannot be changed with ini_set() .
In the list of php.ini directives , they are reportedly of type PHP_INI_PERDIR , which means (as explained in If the configuration parameter can be set ), they can be changed in php.ini, .htaccess or httpd.conf. Configuration parameters that can be changed with ini_set() are referred to as PHP_INI_USER .

+1
source share

SERVER:

In cPanel, find php, you will find "Choose PHP Version" in the "Software" section. Software → Choose PHP Version → Switch to Php Settings → Change Value → Save.

FOR LOCAL:

Locate the PHP ini file (configuration options) in the php folder under xampp. + Change post_max_size = 40M and upload_max_filesize = 40M

0
source share

All Articles