Changing the upload limit in php - php

I am developing a CMS where the clients will need to upload files larger than 2mb - up to 10mb at least. I have changed the details in the php.ini file and I cannot see anywhere else that the problem might be. Any help?
Cheers

Here's what I recommend changing (assuming Apache & PHP):
I've found this works well for up to about 30mb attachments
PHP Settings
max_execution_time = 120
max_input_time = 120
memory_limit = 30M
post_max_size = 30M
upload_max_filesize 30M
file_uploads = On (although it sounds like you already have this turned)
Apache Settings
LimitRequestBody 31457280

You need to set upload_max_filesize, post_max_size and memory_limit appropriately. post_max_size must be larger than upload_max_filesize, because there needs to be memory allocated for the request headers as well as the file payload.

In your php.ini:
; Maximum allowed size for uploaded files.
upload_max_filesize = 50M
; Maximum size of POST data that PHP will accept.
post_max_size = 50M
What errors are you getting in your error log once these have been done? Is it possible that your uploaded file is running foul of the memory limit on the script?
You can set the memory limit higher for this particular script by including the following line in your script:
ini_set("memory_limit","75M");

Make sure you changed upload_max_filesize AND post_max_size

As long as you have restarted your web service (ie apache) then the changes should take effect, however if you are developing for anyone other then yourself then instead of changing the php.ini I would add this to the upload script:
ini_set('upload_max_filesize', '10M');
as some people may not be able to modify php.ini this will change it just for the page it is on.

Related

Upload big file using PHP

I'm trying to upload big files using PHP and it's not working and the size is around 855 ko. I've already tried uploading smaller files and its worked so i'm sure that my problem that causing the error.
I've already tried most of the solution in SO and google but in vain. Some said that i should try to configure my php.ini and i did but without success.
I'm using lighttpd on an embedded system.
My php.ini configuration :
max_execution_time = 300; Maximum execution time of each script, in seconds
max_input_time = 25200; Maximum amount of time each script may spend parsing request data
;max_input_nesting_level = 64 ; Maximum input variable nesting level
memory_limit = 40M ; Maximum amount of memory a script may consume (128MB)
file_uploads = On
upload_tmp_dir =/home/imagesdcard/www/
upload_max_filesize = 10M
max_file_uploads=2
I had tried many solutions that suggesting it was caused by certains configurations in php.ini and i had changed it but without success.So, i wanna ask how can i upload big files using php?
Thank you in advance for all advice and help and have a great day.
By configuration, PHP only allows to upload files up to a certain size. There are lots of articles around the web that explain how to modify this limit. Below are a few of them:
PHP Increase Upload File Size Limit
How do I increase the PHP upload limits?
For instance, you can edit your php.ini file and set:
memory_limit = 32M
upload_max_filesize = 24M
post_max_size = 32M
You will then need to restart apache.

Increasing Upload_Max_Filesize limit

I am facing a little problem with increasing the Upload_Max_Filesize limit on a clients server. The Upload_Max_Filesize is set to 2M and I need to increase it to at least 10M. There's no php.ini file currently present inside any of the folders albeit I tried creating a php.ini file and then uploaded it to the root folder of the website but that didn't work. I also edited the .htaccess file by putting these two lines inside it but, sadly, that didn't work either:
php_value upload_max_filesize 10M
php_value post_max_size 10M
I have access to the cPanel but it's mentioned inside the PHP Configuration page that:
These PHP configuration settings are customizable by the server administrator. They are listed for reference only.
Please let me know if there's any other way through which I can increase the limit of Upload_Max_Filesize.
You have to contact your host to increase your upload size. I've successfully done it from 5mb to 20mb. You just need to ask.

PHP upload limit does not affect. Big files are in /tmp folder

I got the problem with my web server.
I configured PHP to have max upload size 300MB. I changed 2 options in php.ini
php_value upload_max_filesize 300MB
php_value post_max_size 300MB
This works fine.
But recently i noticed very big file in /tmp folder (this is temp folder for PHP).
There were 3 files of a size 1.5GB and continue growing . file names were like temp php files /tmp/php** (** some random code).
And i checked that process writing to these files were my PHP script i created for uploading.
So my question is why PHP upload and post limit didn't affect on these files? What can be the reason? Maybe PHP saves all uploaded data to temp dir first and only after this calculates a size and check if it is good or not?
I appreciate any comments.
UPDATE. Can this be something like - http client sends a request without content-length heder so php can not use post_max_size to limit affect. And PHP writes everything to the disk because doesn't know what is the site of POST request and file in it?
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 = 300M
; Must be greater than or equal to upload_max_filesize
post_max_size = 300M
or in .htaccess
php_value upload_max_filesize 300M
php_value post_max_size 300M
Try to set a new tmp directory with larger space and no limit rather than the system default (/tmp). You can do so either by changing the default directory in the php.ini file:
upload_tmp_dir = /scratch/custom_temp
or overwrite inside the php script:
<?php
ini_set('upload_tmp_dir', '/scratch/custom_temp');
?>

POST Content-Length exceeds the limit

I get similar errors in my error_log in php when users are uploading their files
PHP Warning: POST Content-Length of 11933650 bytes exceeds the limit of 8388608 bytes in Unknown on line 0
In my php.ini (created custom ini file in public_html) would this solve this problem, how much would I have to set it to around 1GB? I am going to change my settings to this in php.ini, will it solve the problem?
upload_max_filesize = 1000M ;1GB
post_max_size = 1000M
What would I set the 'memory_limit' limit to.
Also would this be correct in my script to check file uploaded size is <1GB
if($_FILES["uploadedfile"]["size"]<1000000)
8388608 bytes is 8M, the default limit in PHP. Those changes to php.ini should indeed solve the problem (make sure your restart your Apache server after making them).
Memory limit shouldn't need to be changed here.
I suggest that you should change to post_max_size from 8M to 32M in the php.ini file.
you just setting at php.ini
then set :
upload_max_filesize = 1000M;
post_max_size = 1000M;
then restart your xampp..
Check the image
Try pasting this to .htaccess and it should work.
php_value post_max_size 2000M
php_value upload_max_filesize 2500M
php_value max_execution_time 6000000
php_value max_input_time 6000000
php_value memory_limit 2500M
post_max_size should be slightly bigger than upload_max_filesize, because when uploading using HTTP POST method the text also includes headers with file size and name, etc.
If you want to successfully uppload 1GiB files, you have to set:
upload_max_filesize = 1024M
post_max_size = 1025M
Note, the correct suffix for GB is G, i.e. upload_max_filesize = 1G.
No need to set memory_limit.
In Some cases, you need to increase the maximum execution time.
max_execution_time=30
I made it
max_execution_time=600000
then I was happy.
There might be more than just one php.ini file. For example, when using WAMP there are 2 php.ini files in following directories:
C:\wamp\bin\apache\apache2.4.9\bin
C:\wamp\bin\php\php5.5.12
You need to edit the first one.
I disagree, but the solution to increase the file size in php.ini or .htaccess won't work if the user sends a file larger than allowed by the server application.
I suggest validating this on the front end. For example:
$(document).ready(function() {
$ ('#your_input_file_id').bind('change', function() {
var fileSize = this.files[0].size/1024/1024;
if (fileSize > 2) { // 2M
alert('Your custom message for max file size exceeded');
$('#your_input_file_id').val('');
}
});
});
If you are using Php 5.6.X versions in windows using Wamp, then file location may be in,
C:\Windows\php.ini
Just try with
post_max_size = 100M;
Try to do changes in Apache one. By that your Wamp/XAMP load .ini file
If you are using Laravel and using artisan:serve for running Laravel project you create php.ini in your public directory, then you can specify your configuration.
file_uploads = On
max_execution_time = 300
post_max_size = 20480M
upload_max_filesize = 20480M

How to increase my upload limit in php

I read so many articles out there in the internet and found that to change the php.ini file to upgrade the upload limit. But I do all the suffs and cant upload more than 10mb of files or so.
I am trying to add a feature to upload video file through the front end for users. But failed for some reason
Is there any other way to do it. Or is it because it is a video file or some thing like that
Make sure that you have (in php.ini, .htaccess, etc.):
increased post_max_size to at least twice the max file size that you might need to upload
increased upload_max_filesize to the max file size that you might want to upload
increased memory_limit to something bigger than post_max_size
On top of setting php.ini
upload_max_filesize = 200M
post_max_size = 200M
I owuld look into a flash uploader like uploadify. It will make your life much easier trust me.
Since you are changing the php.ini, are you restarting the webserver so that the changes take effect (if using mod_php)? Does the webserver itself have any restrictions set?
It's been a while since I've done this, but in my php.ini I have upload_max_filesize = 200M and I have post_max_size = 200M
I also set max_execution_time = 3000 If this is set too low, it'll cut off while the user is still uploading.
You should also bump up max_input_time and memory_limit

Categories