Config php ini file for upload files - php

I have a page for upload files, In .htaccess file I have this:
php_value upload_max_filesize 40M
php_value post_max_size 40M
I have an img, with size 1.6 MB. When I am trying to upload this image, I obtain the error below.
Fatal error: Allowed memory size of 54525952 bytes exhausted (tried to allocate 3600 bytes) in....
Does anyone know how to solve this problem?

if you can cant access php.ini on server then write below in your .htaccess file
php_value upload_max_filesize 10M
php_value post_max_size 20M
php_value memory_limit 32M

You need to set following values to increase file upload size
file_uploadsile_uploads
upload_max_filesize
max_input_time
memory_limit
max_execution_time
post_max_size
Cheers

As far as I can tell, you're probably exhausting the memory_limit of PHP, that is, PHP is trying to allocate an amount of memory greater that the memory_limit param value.
Maybe you're uncompressing the image on the fly or copying some data that needs too much memory to be allocated, try increasing that limit.

You have memory_limit in your PHP configuration; 54525952 bytes which is 52MB.
You should configure memory_limit in php.ini or .htaccess or fix memory leak.

Related

How to increase max_upload_size on apache server

In my application, I want to upload a file more than 500 MB, but it's giving me an error as the file is too big to upload.
I tried different ways to increase max_upload_size in php.ini and through .htacccess
but its increased till 128MB not more than that.
is there any way to increase it more than 500MB
Thanks in advance
To upload large files, post_max_size value must be larger than upload_max_filesize.
memory_limit should be larger than post_max_size
memory_limit > post_max_size > upload_max_filesize
PHP Default: 128M > 8M > 2M
So you can try to increase memory_limit as well if you've increased post_max_size and upload_max_filesize
I had the same issue before
I tried this plugin to increase it
https://wordpress.org/plugins/upload-max-file-size/
and
if it's not working you can edit in the htaccess file in WordPress directory and edit the file replacing xx with your preferred value
php_value upload_max_filesize xxM

Increase max file upload size for SilverStripe site

I am working on increasing the max upload file size for a SilverStripe site as I want the new limit to be 20 MB instead of 2 MB. I have placed this line of code in the root .htaccess file for the project:
php_value upload_max_filesize 20M
This works to some extent. It has increased the upload size limit, but only to 8 MB. I removed this line of code and tried uploading a large file again and the "file size exceeds 2 MB" error returned. So, what I have in place does work but only increases the file size limit to 8 MB.
I have been reading that there can be a php.ini file included in the project to increase the file size limit as well, but I am wondering if there is a way to do it through just the .htaccess file?
The reason for this problem is because you've not set your post_max_size. The post_max_size defaults to 8mb. So you need to do the following:
php_value upload_max_filesize 20M
php_value post_max_size 50M
You can obviously edit the post_max_size to something more suitable to what you need.
This 100% work in v4
Your problem is indeed related to php.ini.
In php.ini there is a section related to file uploads that will have the following line in it;
; Maximum allowed size for uploaded files.
upload_max_filesize = 2M
Change the 2M to be something more in line with what you need, then restart apache and you should be good to go.
It is also possible (though i have not tried this yet) to put the following line in to the .htaccess.
php_value upload_max_filesize 20M
Hope that helps.

Increase limit when using fputcsv

I recently asked a question about this, but think after 2 days of troubleshooting I have a better question to ask.
Using fputcsv works great until the file is 4KB or bigger. How can I increase this limit? I have tested the following:
php_value post_max_size 200M
php_value upload_max_filesize 200M
php_value memory_limit 3000M
php_value max_execution_time 259200
php_value max_input_time 259200
php_value session.gc_maxlifetime 1200
and I see the changes being reflected in phpinfo, however apparently none of these are related to the issue.
Any other ideas what global settings might be causing this issue?
Some other things to consider
upload_tmp_dir
The temporary directory used for storing files when doing file upload.
post_max_size
Sets max size of post data allowed. This setting also affects file upload
file_uploads
Whether or not to allow HTTP file uploads.

i have a image sharing script. the max allowed file upload is 5MB what should i set my max_input_time and my max_execution_time?

I ask because since max_input_time is the only that should be set accordingly to facilitate the upload process, how would you ever know what to set it to. Everyone's connection is different some may take longer to upload then others.
Also what are the risks of setting it too high? For example if i choose to allow users to upload bigger files then 5MB.
Please give me as much details as possible on the matter. Thanks.
Use this for big size file upload in .htaccess
php_value memory_limit 300M
php_value upload_max_filesize 200M
php_value post_max_size 200M
php_value max_execution_time 80000
php_value max_input_time 80000

Changing the upload limit in 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.

Categories