Uploading files to server using php - php

I can successfully upload files upto 3-4 MB. But when I try to upload files greater than 4 MB, it starts upload for sometime and then shows "This webpage is not available" error. I have hosted the site in 000webhost. But in localhost, I can easily upload larger files as well. Please help me out of this.

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 = 40M
; Must be greater than or equal to upload_max_filesize
post_max_size = 40M
(and restart apache)

I believe that you have
Enough permission to upload files
And increased upload_max_filesize and post_max_size
upload_max_filesize = 40M
post_max_size = 40M
Note :
000webhost.com is a free hosting site and you can't expect good speed and it would fail in most cases. If you want to see good response better try in a paid hosting or try in some free app hosters like heroku
Update according to user's Comment :
I can do that in localhost. But where can I find the php.ini file as I have already hosted the site
You can't find the php.ini in online server. But you can set it using .htaccess files and other few ways..
Create a .htaccess file and inside it have the following code, then you can achieve your need.
php_value upload_max_filesize 40M
php_value post_max_size 40M

Related

phpMyAdmin giving file to large error even with settings bypass

Alright I am trying to upload a .sql file to phpmyadmin.
I get the error:
You probably tried to upload a file that is too large. Please refer to documentation for a workaround for this limit.
After reading some online solutions, I decided to edit my php.ini to allow bigger file uploads.
I changed this:
Maximum allowed size for uploaded files.
; http://php.net/upload-max-filesize
upload_max_filesize = 2M
to
Maximum allowed size for uploaded files.
; http://php.net/upload-max-filesize
upload_max_filesize = 900M
Then restarted apache with no luck.
How can I bypass this limit? Did I do something wrong? Surely the file can't be bigger than 900M because google chrome reported it to be 15MB when downloading. How can I import this file?
According to https://docs.phpmyadmin.net/en/latest/faq.html?highlight=upload_max_filesize#i-cannot-upload-big-dump-files-memory-http-or-timeout-problems there are two other php.ini settings to adjust, and there is the UploadDir phpMyAdmin feature that gives you the ability of uploading to a temporary directory and import in phpMyAdmin from this directory.
Find the following lines in your php.ini file and update the values as you want.
post_max_size = 8M
upload_max_filesize = 2M
max_execution_time = 30
max_input_time = 60
memory_limit = 8M
Now Restart your apache service.

html5: the upload task is interrupted in php

I've got an alert message when trying to upload very large file in php. When I uploaded 53 MB file and 35% upload process complete, i got an alert message "html5: the upload task is interrupted". I don't know what does that mean. Can anyone help me out. Thank you.
Method # 1: Edit php.ini
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 = 40M
; Must be greater than or equal to upload_max_filesize
post_max_size = 40M
Save and close the file. Restart apache or lighttpd web server:
Method #2: Edit .htaccess
Edit .htaccess file in your root directory. This is useful when you do not have access to php.ini file. In this example, /home/httpd/html is considered as root directory (you can also create .htaccess file locally and than upload it using ftp / sftp / scp client):
Append / modify setting as follows:
php_value upload_max_filesize 10M
php_value post_max_size 20M
php_value memory_limit 32M
otherwise you prefer this link given below:-
1) link
2)link
i hope it helpful for you ...

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');
?>

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