PHP Cannot upload file larger than 40MB - php

On my site, I'm allowing file uploads. I've successfully uploaded a 40 MB file.
But I've been trying to upload a file above 40 mb
In my php.ini, I have the following:
upload_max_filesize = 10G
post_max_size = 10G
max_execution_time = 60
max_input_time = 10000
memory_limit = -1
I work on window server.
I tried a 100mb file. It failed every time.

Instead of
post_max_size = 10G
Try this
upload_max_filesize = 40M
Don't use too big size 10G ,Try with 100M

Are you using php > 5.1. The G modifier is available since PHP 5.1.0.
I think your php doesn't correctly parse the G you are using.
Try:
upload_max_filesize = 10000M
post_max_size = 10000M
Are you sure you want to allow 10 gigabyte? Better to define something close to the max file size you are using. So if it is something like 40 megabyte use 50M.

Related

phpMyAdmin File Limit (already edited php.ini)

I'm trying to import a 151 MB database into phpMyAdmin and am getting the error "You probably tried to upload a file that is too large. Please refer to documentation for a workaround for this limit."
I've already edited php.ini with values of upload_max_filesize, memory_limit and post_max_size that more than accommodate this file. Is there anything else I can do to troubleshoot?
Try setting max_execution_time and max_input_time with higher values.
max_execution_time = 90
max_input_time = 120
You might want to try memory_limit as well and don't forget to restart the server.

Changing post_max_size to 512M not being affected on WAMP

I have read other answers here on stackoverflow, however this is a really weird issue.
My phpinfo() shows that I have set 512M for the post_max_size (I have also increased other properties to at least 512M)
However when I am trying to send post request from Angular HTTP to Laravel 5.2 api, I get 422 Unprocessed Entitym and php_error says:
PHP Warning: Unknown: POST Content-Length of 7323588 bytes exceeds the limit of 3145728 bytes in Unknown on line 0
I have changed both php.ini files,despite only one being loaded.
Step 1: Go to the folder destination where you have installed WAMP. (Usually it is C:)
Step 2: Now locate and open php.ini files from both these locations. (C:\wamp\bin\apache\Apache2.4.4\bin and C:\wamp\bin\php\php5.4.16)
Step 3: Now in both the documents press CTRL+F and find out the following settings.
post_max_size
upload_max_filesize
memory_limit
For example you will see upload_max_filesize = 2m where m is MB. Change 2m to 500m or more as you like.
Change post_max_size = 8m to post_max_size = 700m or more. Change memory_limit = 8m to memory_limit = 1000m.
Other than that to avoid fatal errors like maximum time of something exceeded in line something, find and change the following values.
max_execution_time = 30 to to max_execution_time = 3000 and max_input_time = 60 to 3000.
This was an interesting problem.
The issue was following:
Yes, I needed to change the post_max_size, however at one point in my php.ini I had it set to 1000M.
My Apache 2.4.9 , and PHP 5.5.12 decided to ignore the suffix M and I ended up with a limit of 1000 Bytes.
My solution was to set post_max_size = 1000000 to have the limit set to 1MB

php.ini limit tricks $_FILES['userfile']['size']

In php.ini I have set:
post_max_size = 101M
upload_max_filesize = 101M
memory_limit = 128M
a php upload form uses can upload file up to 100M
a script will check if it doesn't exceed 100M
$img_size = $_FILES['bestand']['size'];
if ($img_size > MAX_EXTRA_FILE_FILE_SIZE){
$errors['tooBig'] = 1;
However, if a user uploads 125M, the server returns the message:
PHP Warning: POST Content-Length of ########### bytes exceeds the limit of ...
and the $error['tooBig'] will lose its value and no error message
will be returned to the user. Of course, i can just increase the ini.php:post_max_size endlessly, but even than a use could upload even larger files.
How do i tackle this?

What's wrong with my php.ini?

i'd like to know whats wring with my php.ini because I cant attach any file more than 200kb. I've already modified the upload_max_filesize and my post_max_size but still nothing happens. I'm using xampp, localhost and php mail() function. Every comment will be much very appreciated. thank you
; Maximum allowed size for uploaded files.
; http://php.net/upload-max-filesize
upload_max_filesize = 20M
; Maximum number of files that can be uploaded via a single request
max_file_uploads = 20
; 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.
; http://php.net/post-max-size
post_max_size = 40M
Many time upload_max_filesize didn't work on windows (xampp and wamp) . I recommend to switch to LAMP Or if you have to upload database you can use MYSQL workbench on windows system .

upload large file in php

How can I upload files larger than 2MB in PHP,I searched the Internet and i changed the php.ini file,the line is: "upload_max_filesize = 200M",but I still can't upload even 2 MB file.
What seems to be the problem?
Please help me.Thanks in advance.
Once upon a time I'm facing this problem with my WAMP server, and when I search for solution, I stumbled upon to this discussion. So, if someone have the same problem, this is my working solution, I hope this help:
I'm using WAMP stack. By reading your comment above, you are using WAMP stack too. In case you don't know, WAMP server has 2 (two) php.ini (in PHP directory and Apache directory) configuration, one for CLI and the other for Apache itself ( see php.ini on WAMP server ). So, I create info.php to detect which php.ini use by my server, and in my case that is the one in Apache directory ( see Which PHP Ini file does my WAMP webpage uses?).
Open your php.ini that used by your server, and as #Pascal Martin suggested, change upload_max_filesizeand also set post_max_size then restart your server.
Check again your info.php, make sure the value of upload_max_filesize and post_max_size has changed to your desired value.
Restart Apache.
It's worked for me, hope this help.
As you guessed, you have to set upload_max_filesize...
But you also have to set post_max_size (quoting) :
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.
There are also other options which could limit this:
max_input_time = 600
php_value max_execution_time = 600
post_max_size = 200M
(...and restart Apache)
get your php.ini-dist file,
edit it to set proper values shown above
rename it to php.ini
copy it in WINDOWS directory
restart Apache
Put the following code in side the .htaccess file and save it.
php_value upload_max_filesize 200M
php_value post_max_size 200M
php_value max_input_time 2000
To upload the larger file, one needs to change/increase the value of both post_max_size and upload_max_filesize directives from the php.ini file.
upload_max_filesize = 200M
post_max_size = 201M
This will increase upload limits on a single file to 200 MB, from the default of 2 MB.
To upload a large file ( >5MB), I use the chuck upload method.
/**
* #param $file
* #param $fileSize
* #param $name
* #return int
*/
public function chunkUpload($file, $fileSize, $applicantID, $name) {
$targetFile = 'upload/'. $name;
$chunkSize = 256; // chunk in bytes
$uploadStart = 0;
$handle = fopen($file, "rb");
$fp = fopen($targetFile, 'w');
# Start uploading
try {
while($uploadStart < $fileSize) {
$contents = fread($handle, $chunkSize);
fwrite($fp, $contents);
$uploadStart += strlen($contents);
fseek($handle, $uploadStart);
}
fclose($handle);
fclose($fp);
return 200;
} catch (\Exception $e) {
return 400;
}
}
Changed the server settings in this way...
memory_limit = 250M //The maximum amount of memory in bytes a script is allowed to allocate.
max_input_time = 600 //The maximum time in seconds a script is allowed to parse input data.
max_execution_time = 600 //The maximum time in seconds a script is allowed to run before it is terminated.
post_max_size = 200M //The maximum size in bytes of data that can be posted with the POST method. Typically, should be larger than upload_max_filesize and smaller than memory_limit.
upload_max_filesize = 100M //The maximum size in bytes of an uploaded file.
Try setting it with within PHP script (on top)..
ini_set("upload_max_filesize", "255M");
ini_set("post_max_size, "256M");

Categories