Increase file upload size but cannot locate/access php.ini - php

I'm testing a file uploading page etc that I'm working on. Chose a largish file at random and received:
Request Entity Too Large
The requested resource
/admin.php
does not allow request data with POST requests, or the amount of data provided in the request exceeds the capacity limit.
as an error message. Brief google led to changing values in php.ini but I can't locate or access it.
The site is hosted on a free site 000.webhosting.org - I'm guessing they have it restricted somehow. Is there a workaround?

Create an .htaccess document and put it in you document root directory. Inside, place:
php_value upload_max_filesize 10M
Source: http://www.cyberciti.biz/faq/linux-unix-apache-increase-php-upload-limit/
Honestly, I've never tried this, but it appears to be what you need.
Edit:
Here's something else I found, you can try: ini_set("upload_max_filesize", "xM"); where x is a number and the M signifies Megabytes. I'm not sure if it works with all versions, but it's listed as being editable on the php website (http://www.php.net/manual/en/ini.list.php).

Related

"413 Request Entity Too Large" for AJAX POST request but not for normal file upload

My environment is a shared hosting package by 1und1 (1and1). Locally on my laptop, everything works fine.
I'm sending quite a large AJAX request to the server (~1.2MB) which worked fine for a long time now. However, a few days ago it stopped working and I keep getting the following response:
413 Request Entity Too Large
The requested resource
[my request URL] does not allow
request data with POST requests, or the amount of data provided in the
request exceeds the capacity limit.
When I lower the size of the POST parameter (a long JSON-string), then everything works as expected. The limit is somewhere around 1MB (determined by trial and error).
I've found a lot of suggestions what the cause could be. E.g. the following php config values. However, they are more liberal than the ones on my local machine and I cannot see where they could be a limit here:
max_input_time = -1
max_execution_time = 50000
upload_max_filesize = 64M
post_max_size = 64M
memory_limit = 256M
Then, another config value often appears in solutions, the apache config LimitRequestBody. The problem here is: AFAIK I don't have acccess to changing it on the 1and1 shared hosting - and I cannot find a way to view the apache error log...
I initially thought that the LimitRequestBody must be the cause.
But why can I upload files via a normal POST HTML file form then (tested with a 4MB file) on the same server (using the Symfony 2 form builder with a filetype object which seems to translate into a standard HTML file upload form)? As far was I understand the LimitRequestBody (and if applicable also SecRequestBodyNoFilesLimit) value, it should also cause the same error here, if it really was the cause, right?
So does anyone has another idea what I could do to debug this error any further? Or has a solution to my question above? Or at least any ideas how to workaround this?
PS:
SSLRenegBufferSize should not be relevant when accessing the webpage without https, right?
413 errors occur when the request body is larger than the server is configured to allow, and there is only so much you can do especially if the server it not under your control. Here’s is an idea:
Ask your hosting company to set the LimitRequestBody directive in either your httpd.conf file or a local .htaccess file to be higher. More Info

File upload 404 error on server

I have a PHP file up-loader that we use to upload around 10-15 5mb images every day. I have the image uploader locally and i can upload images fine. I changed all the settings in my php.ini to ensure than i had the correct limits.
Now, i have put the up-loader on a windows server and it has the same settings, but sometimes (not always) when i upload 10-15 images it gets to 97 percent and throws a 404 document not found error.
Does anyone have any ideas as to why this could happen? I have been trying to sort this for days it is really frustrating. I'musing php 5.6 on iis.
IIS returns a 404 error when a POST length is too large:
HTTP Error 404.13 - CONTENT_LENGTH_TOO_LARGE
You'll need to increase the file upload limit using the parameter:
requestLimits.maxAllowedContentLength
Details of both of these items are on the IIS website:
https://www.iis.net/configreference/system.webserver/security/requestfiltering/requestlimits
For me it turned out to be neither of the PHP or any settings for maximum filesize setting in php.ini.
The IIS on the other hand limited the post upload size.
To change go to your website in the IIS Manager
Click on Request filtering
In the right pane select Edit Feature settings
Change the Maximum allowed content length to your desired byte length which is the maximum value (we used 100MB or 104857600 bytes)

Can't upload large file in Laravel (php.ini settings are correct in my opinion)

I have the following problem in Laravel.
I would like to upload a file through a form. But for some reason if the file is larger than around 2100 KB, the validation fails, and says that the file is 'required' and I did not provide it.
I've read numerous articles, that this can be because of php.ini settings. On my server they are the following:
upload_max_filesize 64M
post_max_size 64M
These values are copied from the output of phpinfo(), so they are in effect.
And despite this, the upload fails even for a 2 MB file. Do you have any ideas what I could check/set to solve this?
I am using laravel 5.2, and PHP 7.
Check which server software you are using. Nginx for instance has it's own limit (default set to 1MB I believe). Apache might have it too. Consult the respective manuals for those packages on how to configure them. Or if you're using shared hosting, contact support to see if they can increase the limit.
Though this isn't a really scalable solution. Next time you might want to upload a 100MB file, and you probably don't want to allow 100MB requests on your servers. A better approach would be to split the file in smaller chunks in the frontend, with JavaScript, and submit them as parts of the same upload, then recombine the parts on the server once the file is completely uploaded. Beware of additional checks you'll have to do here though.
You might want to incorporate the following into your own code:
<?php
//--- this tries to override the default of only 2M file uploads.
ini_set("upload_max_filesize","25M");
ini_set("max_execution_time",600); //--- 10 minutes
ini_set("post_max_size","35M");
ini_set("file_uploads","On");
?>
In my case, it was HDD space issue. not enough space to store the file.
Laravel should handle it with proper message, instead of indicating user didn't upload anything.
If you are not using any other package to upload files to check , then
then remember to restart apache .

Can't upload file

I've made an CMS for a customer. One of the things he can do is upload a PDF file. We've tested this thoroughly and haven't encountered any bugs. However, he can't seem to upload anything at all. The file is never uploaded. His browser just keeps loading.
My client uses Firefox (not sure which version but I thought that wouldn't matter) and the PDF files he attempts to upload are around 5MB, nothing extreme.
Is there any reason why a browser doesn't finish it's request when uploading a file? I don't think the files are corrupt.
I don't think the problem lies in my script... but still worth posting:
if(!empty($_FILES['pdf'])) {
$path = '../pdf/';
$filename = $_FILES['pdf']['name'];
if(!empty($assoc['pdf'])) {
$oldfile = $path.$assoc['pdf'];
if(file_exists($oldfile)) {
unset($oldfile);
}
}
$success = move_uploaded_file($_FILES['pdf']['tmp_name'], $path.$filename);
}
Edit: He has sent me the PDF he's trying to upload. Took about 10 seconds to upload... I'm providing him a link to do a speed test, lol.
You can have two problems i see, might not be your exact problems but could lead you to your answer.
#1. POST_MAX_SIZE or UPLOAD_MAX_FILESIZE is not big enough
There are two configs that php programmers often forget about and this is probably your most obvious problem. Your tests have been done but have they been done with large files?
Using an htaccess or a php.ini (depending on your server configuration) you can override the php settings for
upload_max_filesize
post_max_size
And give them 20M for example:
/*.HTACCESS*/
php_value upload_max_filesize 20M
php_value post_max_size 20M
/*PHP.INI*/
upload_max_filesize = 20M
post_max_size = 20M
You cannot use ini_set() because these variables are used BEFORE php starts processing and thus would become useless in the context.
#2. enctype is not multipart/form-data
Although very unprobable, you might have forgot to set your enctype property on your form to "multipart/form-data" and thus, nothing gets sent to the server at all. But i doubt this is your issue since you said you tested it extensively.
BUT, sometimes, we move things around and forget to test (it happens to me too) and i was sure something worked before and now it's not, so check it out just to make sure :)
Good luck
Have the client try uploading the file in a different browser than Firefox. If it works in others browsers, try deleting (or renaming/moving, for testing purposes) the file MimeTypes.rdf in the client's Firefox profile folder.
If the PDF upload works afterwards, you encountered a Firefox bug that was first reported in 2007 (basically the same here, reported in 2006). In a nutshell, any web site from which the user ever downloads a file has the potential to corrupt the MimeTypes.rdf file in regards to the extension of the downloaded file - maliciously or accidentally/unknowingly.
Things you can do:
Vote for the Firefox bug!
Quick fix to get it working for the client right now: Have the user(s) delete their MimeTypes.rdf file. Firefox will create a new, "fresh" one at the next start, but this will clear all MIME type / application associations that the user has created over time. Also, this will only help until the user downloads the next PDF file from some other web site that corrupts the MimeTypes.rdf file again.
Use the "user agent" header to determine if the file is uploaded from Firefox. If so and the MIME type doesn't match anything you wish to accept, double-check the file name's extension and accept the file anyway if the extension matches your accepted file type(s) (".pdf" in your case).

Upload File Size Limit: Symfony Admin Generator Module

I have form created by the admin generator in the backend of a website. It allows the upload of a video to the site.
It works fine but strangely, the upload fails for files of 10mb or over. However, I have not set any file limits in my form.
Are there Symfony/PHP/Apache/web browser settings regarding this type of behaviour that I can look into?
Or is there a way I can inform Symfony that I'd like to permit larger files?
Even I haven't ever worked with Symfony I expect the problem due to limitations on your Web-Server.
If you have the possibility to edit or add your .htaccess file then the following line of code will probably help you:
php_value upload_max_filesize 100M
the 100M in example is for 100 Megabyte.
Also make sure that (at a minimum) you update post_max_size to match. See the PHP documentation, especially the sections on "Common Pitfalls" and "Error Messages Explained".

Categories