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?
Related
public function add_video()
{
if(isset($_POST['add']) && $_POST['add']=='ADD')
{
move_uploaded_file($_FILES['video']['tmp_name'],'uploadimg/'.$_FILES['video']['name']);
$data = array('id'=>'', 'title'=>$_POST['title'],'video'=>$_FILES['video']['name'],'url'=>$_POST['link'],'status'=>$_POST['status'],'date'=>$_POST['date']);
$this->Dbfunction->insertdata('videos',$data);
redirect(base_url().'index.php/admin/videos');
}
}
And I Got Following Error
Warning: POST Content-Length of 177938307 bytes exceeds the limit of 8388608 bytes in Unknown on line 0
Database Table Structure is follows
enter image description here
Try to set upload_max_filesize and post_max_size to 0 in php.ini
Create a file in PHP containing:
file.php
<----------- start -------------->
<?php
phpinfo();
<----------- end -------------->
Locate the line (Core): upload_max_filesize
If it is not the value you set in the php.ini file, or you changed the wrong file, or you did not restart apache
Also remember that you need to increase post_max_size and memory_limit too.
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
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.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
POST Content-Length exceeds the limit
PHP Warning: POST Content-Length of 113 bytes exceeds the limit of -1988100096 bytes in Unknown
I have form for upload images, I testing and if I upload image, where have for example 9 mb size, php returns error:
POST Content-Length of 10194008 bytes exceeds the limit of 8388608 bytes in Unknown on line 0
I want that dont upload files more than 2 mb, in first line I have this code:
if (!empty($_FILES['main_photo']['name'])) {
if ( $_FILES['main_photo']['size'] > 1024 * 1024 * 2 ) {
header("Location: index.php");
exit();
}
}
but this error still displayed, please tell what make, I want if file more than 2 mb, just:
header("Location: index.php");
In php.ini look for upload_max_filesize and post_max_size and set to a suitable size:
upload_max_filesize = 20M
post_max_size = 20M
Only after that changes you can add your redirection code.
If you can't access your php.ini (shared hosting) try in .htaccess:
php_value upload_max_filesize 20M
php_value post_max_size 20M
The file you are trying to upload is larger than the configured size set in php.ini. Go inside of php.ini and modify these values to 2mb or greater to allow larger uploads:
upload_max_filesize
post_max_size <-- This one appears to be your biggest issue
Then your code should work.
Your server probably has setting to limit size to 8 megabytes, I think you code is ok. its a server problem try setting the upload_max_filesize using ini_set to something more. If you are one a commercial server , not your own, try contacting administrator
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");