15

I have a page which allows users to upload images.

It is returning a 500 error when the user tries to upload larger images though.

The following code...

<?php echo ini_get("upload_max_filesize"); 
echo ini_get("post_max_size"); 
echo ini_get("max_input_time");
echo ini_get("max_execution_time");
?>

...returns:

100M
100M
60
3600

I'm guessing from this that it's the max-input-time that's causing the problem as i've tested with files under 100mb but taking longer than 60 seconds to upload.

I don't have access with my host to the php.ini file, so can I override these settings? I've tried adding an htaccess file but I'm not sure I've put it in the correct place.

Tom
  • 12,776
  • 48
  • 145
  • 240

2 Answers2

25

Put a .htaccess file in the root folder of your website (where your php script is) and add the following values:

php_value upload_max_filesize 100M
php_value post_max_size 100M
php_value max_execution_time 200
php_value max_input_time 200

Of course, you can put other size and time limits. That should work.

Aleksandar Vucetic
  • 14,715
  • 9
  • 53
  • 56
  • OK, so I did that and set crazy high values to make sure and still no joy. Could it be something else? – Tom Jan 10 '12 at 23:56
  • If you are on shared hosting (and you most likely are since you cannot change your php.ini), it might happen that your hosting provider doesn't allow php.ini to be overriden using .htaccess. In that case, just ask them how to do that. – Aleksandar Vucetic Jan 11 '12 at 00:24
  • Also, inside your php file, can you put: ini_set('upload_max_filesize', '20M'); etc... just to make sure that you didn't put your .htaccess in the wrong place. – Aleksandar Vucetic Jan 11 '12 at 00:28
  • I tried your last suggestion but it would appear I am only allowed to change the max_execution_time using this method. – Tom Jan 11 '12 at 11:18
  • Your shared hosting probably doesn't allow any other changes. You should contact them and ask how to do that. – Aleksandar Vucetic Jan 11 '12 at 14:55
  • The hosts have prevented over-riding these settings... I think I need a re-think! – Tom Jan 12 '12 at 10:44
1

Setting up php ini directives depends on the nature of your service provider's configuration. Run a phpinfo() script to look at your configuration. If your provider is starting PHP using suPHP in a user UID context then it may look for a php.ini in the script's directory. This is how it works for my hosting provider.

TerryE
  • 10,724
  • 5
  • 26
  • 48