5

I trying to use PHP's file upload abilities, but when I try to upload certain file sizes (9MB for example) it's not going through. Smaller files goes fine.

Even when I set error reporting to be on "E_ALL" and try and upload a bigger file. I don't see any error message.

I have tried setting these lines at the top of the PHP script that uploads the files but still no go:

ini_set('memory_limit', '96M');
ini_set('post_max_size', '96M');
ini_set('upload_max_filesize', '96M');
2
  • I'm guessing it's a server-imposed limit, but I haven't touched PHP in some time. Commented Sep 12, 2010 at 7:48
  • What happens if you output print_r($_FILES);? The array may contain an error code. Commented Sep 12, 2010 at 8:14

4 Answers 4

6

Take a look at the list of parameters for PHP and where you can set them. If I read that list correctly, post_max_size and upload_max_filesize can only be set in php.ini, not via ini_set.

Set those values in the appropriate php.ini (there are different ones for CLI and mod_php), or if you don't have access to the main php.ini create a php.ini in your folder.

To check if the settings work, create a phpinfo file and check the values.

Sign up to request clarification or add additional context in comments.

1 Comment

True enough. By the time the PHP script fires up and changes those .ini settings, the upload has already been completed/aborted. They can only be changed at the webserver level (php.ini and/or httpd/conf and/or .htaccess)
2

try changing the php.ini file which is having certain properties.

you can change all the properties that u have mentioned in your php file into your ini file this worked for me. Try if it works for u as well

2 Comments

What is the difference between setting it via ini_set or changing it in the php.ini file?
@Or W setting the maximum upload size via ini_set will not work, because the uploaded file will be present at the time the script starts.
0

Try setting a MAX_FILE_SIZE entry in the form.

<input type="hidden" name="MAX_FILE_SIZE" value="100663296" />

where the number is in bytes. Additionally, try changing the PHP settings in either php.ini or a .htaccess file in the same directory. The syntax for php settings in htaccess files are:

php_value name value

So you would say:

php_value memory_limit 96M
php_value post_max_size 96M
php_value upload_max_filesize 96M

Also, are you using your own server, or some online host. Some online hosts set a maximum file upload limit that you have to change in the Control Panel (depending on what interface the host uses), or they just plain don't let you change the max file size.

5 Comments

Adding the hidden input did not help.. What is the difference between setting these three settings via ini_set or changing it in the php.ini file?
No, this field is useless. Get rid of it if you have it already
Okay, the extra field is there just as a safe measure because some (uncommon) browsers automatically assume a max file size of 10M if it is omitted. Changing the setting in the php.ini file is the most definitive way, but it changes it for ALL of your pages. Setting it in the .htaccess changes it just for the folder it is in. Setting the value in the PHP file with ini_set changes just that individual file's setting. Since the ini_set doesn't seem to be working for you, I'm just suggesting that you try one of the other two options to see if it helps to solve the problem.
Changing the ini settings in the script has no effect whatsoever. The upload is completed or aborted long before the script is started up, so the ini changes are moot. They have to be in the httpd.conf and/or php.ini and/or .htaccess
Have you done what the others said and print_r($_FILES)? See what it says when you do that.
0

I don't see any error message.

that's because file uploads has it's own error messages. check $_FILES['filename']['error']

I have tried setting these lines

but you didn't check if it has any effect! run phpinfo() to see actual values

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.