Strange PHP error, where does it come from? Codeigniter - php

Today i was making a file upload for avatars, everything works great, it resizes the images etc, but occasionally when selecting a large and invalid file it produces this error :
Warning: POST Content-Length of 52091839 bytes exceeds the limit of 8388608 bytes in Unknown on line 0
You did not select a file to upload.
This does not happen all the time, just occasionally. Normally it just gives the correct error message when a file is too big.
Does anyone have an idea where this error comes from, and why it shows?
Thanks!

Sounds like you need to increase post_max_size in php.ini. If you have not already also increased upload_max_filesize, you are likely to need to increase it as well.
# php.ini
# Allow huge files:
# Post usually needs to be bigger than file upload size!
post_max_size = 256M
upload_max_filesize 128M

Update your post_max_size in php.ini to a larger value
upload_max_filesize sets the max file size that a user can upload while post_max_size sets the maximum amount of data that can be sent via a POST in a form. That might be the reason why you get big file error sometimes when you try upload a single file of large size but when you try to upload multiple files the above error is raised.

This has to do with the way the file is coded when uploaded.
Basically it is "seen" as a very large POST.
So you want your php.ini post_max_size larger than your upload_max_filesize value.
Depending on the encoding you use, it should be from 60% to 100% larger.
Otherwise you might have a max file size of 5 M, but this gets encoded to 8.01 M; when that happens, the check for file size passes, but the one for post body size fails. Hence your error.

Related

Server issue with large file upload?

I have a dedicated server Linux WHM/Cpanel that hosts a video streaming website. I have a form to upload videos and I've been trying to upload larger files but failing? I've checked error logs and nothing is leading me in the right direction. Below are my php.ini settings
upload_max_filesize = 1200M
post_max_size = 1200M
max_input_vars = 1000
memory_limit = -1
max_file_uploads = 20
max_execution_time = 7200
max_input_time = 7200
max_input_vars = 1000
I can upload a 100MB file just fine but the movies i have can be up to 1gb. I'm using Plupload to upload files. I've tested several small size files and they upload fine. When I try to upload large movies e.g. 300mb, Plupload returns this error HTTP Error. Upload URL might be wrong or doesn't exist. and this is the only clue I have. Plupload uses chunking to split up large files also.
This only happens with larger files. It's really a nuisance also, since I have to upload large files all over again to see if my changes are successful or not.
Any ideas? Why would it work with a smaller size file but not larger? I have no errors to work from.
HTTP Error is common when there is something wrong with the files being uploaded. Please check your server info with php.ini
upload_max_filesize is the limit of any single file.
post_max_size is the limit of the entire body of the request,
Sometimes the server requires post_max_size greater than upload_max_filesize I might be wrong but I have to check.
Try debugging the issue removing the chunking first and then later add the chunking part when you remove those HTTP errors.

PHP Is post_max_size the size of all inputs added up together? [duplicate]

When trying to upload a PDF file that was 15mb through an admin area created for doing so, nothing happened. There was no success or error message, but the PDF did not upload.
I then thought that it could be an issue with the php.ini settings. Sure enough, when I looked at the file, I found that the limits were set to 8m. Which I'm assuming means 8mb.
post_max_size: http://php.net/post-max-size
; Maximum size of POST data that PHP will accept.
; Its value may be 0 to disable the limit. It is ignored if POST data reading
; is disabled through enable_post_data_reading.
post_max_size = 20M
upload_max_filesize: http://php.net/upload-max-filesize
; Maximum allowed size for uploaded files.
upload_max_filesize = 20M
Looking at the comments, it appears that one is for files being uploaded, while the other relates directly to POST data. What I'm confused about is this scenario: If you have a form that is POST'ing an image to another page, what does that count as, upload_max_filesize or post_max_size? Does it fall under both? Does one take precedence? Are there cases where one would be used and not the other?
Edit:
So if I have a form that has 3 file inputs, all allowing files 20mb or smaller, the settings would have to be set like so:
upload_max_filesize = 20M
post_max_size = 60M
You are correct. post_max_size is the maximum size for all POST body data. It doesn't matter if you're POSTing JSON or your DVD collection, this is all POST body data. Your file upload counts towards this limit. You should also be aware that if you are uploading multiple files, the total file size has to fit within this limit.
upload_max_filesize is a maximum size only for files that are POSTed. Other types of POST body data are not subject to this limit.
In short, if you want to upload large files, you must increase both limits.
post_max_size is like the superset. upload_max_filesize is in context with file uploads but post_max_size is checked for all kind of POST data. It can be a very big content which can be posted which is limited by post_max_size. So for a big file you want to upload, you need to change both the limits.

PHP post_max_size vs upload_max_filesize, what is the difference?

When trying to upload a PDF file that was 15mb through an admin area created for doing so, nothing happened. There was no success or error message, but the PDF did not upload.
I then thought that it could be an issue with the php.ini settings. Sure enough, when I looked at the file, I found that the limits were set to 8m. Which I'm assuming means 8mb.
post_max_size: http://php.net/post-max-size
; Maximum size of POST data that PHP will accept.
; Its value may be 0 to disable the limit. It is ignored if POST data reading
; is disabled through enable_post_data_reading.
post_max_size = 20M
upload_max_filesize: http://php.net/upload-max-filesize
; Maximum allowed size for uploaded files.
upload_max_filesize = 20M
Looking at the comments, it appears that one is for files being uploaded, while the other relates directly to POST data. What I'm confused about is this scenario: If you have a form that is POST'ing an image to another page, what does that count as, upload_max_filesize or post_max_size? Does it fall under both? Does one take precedence? Are there cases where one would be used and not the other?
Edit:
So if I have a form that has 3 file inputs, all allowing files 20mb or smaller, the settings would have to be set like so:
upload_max_filesize = 20M
post_max_size = 60M
You are correct. post_max_size is the maximum size for all POST body data. It doesn't matter if you're POSTing JSON or your DVD collection, this is all POST body data. Your file upload counts towards this limit. You should also be aware that if you are uploading multiple files, the total file size has to fit within this limit.
upload_max_filesize is a maximum size only for files that are POSTed. Other types of POST body data are not subject to this limit.
In short, if you want to upload large files, you must increase both limits.
post_max_size is like the superset. upload_max_filesize is in context with file uploads but post_max_size is checked for all kind of POST data. It can be a very big content which can be posted which is limited by post_max_size. So for a big file you want to upload, you need to change both the limits.

The maximum file size uploaded using PHP and html5?

Any idea on how big the file size could one file uploaded using php and html5?
And
Is there any suggestions on good components or example to do this?
thanks a lot!
On the server side the maximum upload size is limited by php post_max_size and upload_max_filezize.
Also your webserver can limit the maximum size of your post body. E.g. Apache limitrequestbody which defaults to 0 = unlimited or nginx client_max_body_size which defaults to 2MB
If you are planning to upload large files using html5 you might want to have a look at file.slice which is supported by all modern browsers
Support for .slice in the File API
Firefox supports the Blob API and the .slice APIs that come with it. This can help people who want to process parts of large File objects from JavaScript without having to load the whole file into the memory. People who reliably upload large files can use some server and JS code to split a large file into sections and upload chunks, including re-retrying failed sections, or even uploading several sections, in parallel.
Using this, you could upload giant files in chunks and merge them on the server-side again.
EDIT
Found this great article which explains html5 uploads by streaming via xhr
http://www.webiny.com/blog/2012/05/07/webiny-file-upload-with-html5-and-ajax-using-php-streams/
This procedure has a very low memory footprint, you might still run into the webserver and php upload limits because this is done with a single request. The code should give you an idea on how the whole technology works.
PHP's pretty crappy when it comes to large file uploads, particularly because you have to a memory limit higher than the size of the file. As well, Apache on 32bit systems tends to have a 2gig file limit itself, so even if PHP could handle the upload, Apache will choke.
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
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.
The maximum size of an uploaded file is integer.
When an integer is used, the value is measured in bytes
The maximum file size value is defined in phi.ini file.
search this in php.ini
Maximum allowed size for uploaded files.
upload_max_filesize = 32M

move_uploaded_file file disappears from tmp but does not reach destination

I have a really odd problem. I am using an upload form to upload videos. Sometimes I have to try twice to upload a file so I know it works but these files take a long time to upload so I don't want the end-user getting mad if the process fails. Also, this works 100% of the time on my test machine so I am thinking there is a config problem.
The file is 330mb and I set upload_max_filesize and post_max_size to 500mb. The max_execution_time and max_input_time are set to 60000 for testing purposes. memory_limit is what I think may be the problem. It is set to 128mb. Does it need to be higher to have a consistent upload success rate? Anybody know of any other problems that could cause things to go wrong?
You're right in assuming memory_limit is your culprit.
Taken from php.net.
post_max_size (int)
Sets max size of post data allowed. This setting also affects file upload. To upload large files, this value must be larger than upload_max_filesize.
If memory limit is enabled by your configure script, memory_limit also affects file uploading. Generally speaking, memory_limit should be larger than post_max_size. When an integer is used, the value is measured in bytes. Shorthand notation, as described in this FAQ, may also be used. (...)

Categories