PHP upload size and its impact on post size and memory limit
post_max_size
should be3G
upload_max_filesize
should be3G
memory_limit
depends!!! what you are going to do with the file. If you are going to manipulate the file or do other memory intensive jobs, then you will need to set a high limit. If you don't want to put a maximum limit, you can always set it to-1
. This value doesn't have to do much with the size of the file, but rather with the size of the physical memory your script needs to handle the job.
For the first two, it is the maximum file size you expect to be uploaded, suffixed with a short hand byte value. For KB
should be K
, MB
should be M
, GB
should be G
, ...
Relationship between php’s memory_limit, upload_max_filesize and post_max_filesize
PHP will accept uploaded files that are individually smaller than upload_max_filesize
and together take less than post_max_size
bytes. The PHP documentation is wrong with regard to memory_limit
which does not need to hold the file contents posted.
The following configuration works with both Apache2 module and CGI, and accepts files smaller than 1G.
upload_max_filesize = 1G
post_max_size = 1G
memory_limit = 32M
PHP - Maximum Total Upload Size?
Yes. There are (as far as I can remember) three or so configuration settings which will affect upload size restrictions:
upload_max_filesize
, which sets an upper limit on the size of uploaded filespost_max_size
, which limits the total size of posted data, including file datamax_input_time
, which restricts the length of time the script is allowed to process input data, including posted values
upload_max_filesize
is a limit on each individual file; however, post_max_size
is an upper limit on the entire request, which includes all the uploaded files.
Different hosting environments will have these values set differently, which may affect your abilities upon deployment.
up to how much memory limit can be set POST method in PHP? Maximum how much?
The HTTP standard doesn't specify any limits for post requests, so the limits will either come from
- Your web server configuration (.htaccess)
- Your PHP configuration (php.ini)
- The client (browser)
I just performed a small test locally and I was able to upload a 9.1GB video file using Apache, PHP 7 and Google Chrome.
Change the maximum upload file size
You need to set the value of upload_max_filesize
and post_max_size
in your php.ini
:
; Maximum allowed size for uploaded files.
upload_max_filesize = 40M
; Must be greater than or equal to upload_max_filesize
post_max_size = 40M
After modifying php.ini
file(s), you need to restart your HTTP server to use the new configuration.
If you can't change your php.ini
, you're out of luck. You cannot change these values at run-time; uploads of file larger than the value specified in php.ini
will have failed by the time execution reaches your call to ini_set
.
See the Description of core php.ini
directives.
Import file size limit in PHPMyAdmin
You probably didn't restart your server ;)
Or you modified the wrong php.ini
.
Or you actually managed to do both ^^
When uploading a very large file in PHP, how much RAM is required on the server?
No, memory_limit need not be greater than post_max_size.
PHP has different POST readers and handlers depending on the content type of the request. In case of "multipart/form-data" (what is used for sending files), rfc1867_post_handler
acts as a mixed reader/handler. It populates both $_POST
and $_FILES
. What goes into $_POST
counts towards the memory limit, what goes into $_FILES
also counts.
However, $_FILES
has just meta-data about the files, not the files themselves. Those are just written into the disk and hence don't count towards the memory limit.
Uploading images with PHP and hitting the script memory limit
The actual problem is not with the initial file size but with the dimensions of the image itself (heightwidthcolorDepth), since you don't have access to this information before the file has been uploaded for security reasons, you should probably use an uploader written in Flash, Java or Silverlight since they DO have access to this information beforehand.
After the upload you can check if the image will exceed your memory limit by calculating the dimensions of the (uncompressed) image by using getimagesize and using the returned width, height and bit depth.
Best of luck.
Related Topics
MySQL Stored Function to Create a Slug
Properly Escaping with MySQLi | Query Over Prepared Statements
Cannot Initialize Mbstring with PHP 7
Php: Most Frequent Value in Array
How to Apply Url Normalization Rules in PHP
Quoting Constants in PHP: "This Is a My_Constant"
Regular Expressions: How to Express \W Without Underscore
Increment Behavior on Strings - PHP Easter Egg
Retrieving Get and Post Data Inside Laravel Controller
PHP Session Variables Not Being Maintaned
PHP Array, Are Array Indexes Case Sensitive
How to Download Blob Based File from MySQL Database in PHP
Finding Common Value Among Sub-Arrays in a Multidimensional Array
Pdo Last Insert Id Always the Right One
Cakephp Cake_Core_ Cache Was Unable to Write 'Cake_Dev_En-Us'
How to Disable Adding Properties into a Class from an Instance of the Class
Sqlite Database Hosted on Heroku Getting Automatically Reset