Page 1 of 1

Image size restrictions

Posted: Sun Dec 16, 2007 8:20 am
by mikeym
Hi,

I'm having a problem with creating a form to upload images to my webpage using php. I can get the upload to work normlly but my server has a file size restriction of 500Kb and if I select a file larger than this the form loads an error without ever reaching my php code to process it. Is there a way round this?

Posted: Sun Dec 16, 2007 9:20 am
by anjanesh
You can increase it if you can edit your server's php.ini file.
Look for upload_max_filesize in php.ini
Also increase your post_max_size value too.

Im not sure if ini_set accepts these attributes ...

Code: Select all

ini_set('upload_max_filesize', '10M');
ini_set('post_max_size', '20M');

Posted: Sun Dec 16, 2007 10:10 am
by mikeym
I was thinking of something more like

Code: Select all

<input type="file" name="file" accept="image/jpeg" maxlength="500000" />
as I don't host my own site. Unfortunately at least Firefox doesn't support this method. Is there anyway to get something better than a page not found error if someone tries a file over 500Kb. Perhaps I could check the file locally using Javascript???? It doesn't have to be secure because they can't load it up anyway!

Posted: Sun Dec 16, 2007 10:16 am
by John Cartwright
mikeym wrote:I was thinking of something more like

Code: Select all

<input type="file" name="file" accept="image/jpeg" maxlength="500000" />
as I don't host my own site. Unfortunately at least Firefox doesn't support this method. Is there anyway to get something better than a page not found error if someone tries a file over 500Kb. Perhaps I could check the file locally using Javascript???? It doesn't have to be secure because they can't load it up anyway!
I hate this method, and it can NEVER be relied on. Javascript is not an option here in this case since it does not have access to the users filesystem.

Have you tried anjanesh's suggestion?

Posted: Sun Dec 16, 2007 10:45 am
by anjanesh
Also try creating a .htaccess file in your main folder and have this text in that file:

Code: Select all

php_value upload_max_filesize 10M
php_value post_max_size 20M
You may need to verify the attribute names.

Posted: Sun Dec 16, 2007 11:35 am
by mikeym
This method does work (ie it does what it's supposed to) but completely fails to sort my problem. The issue is that as soon as I try to initiate a upload of a file over 500Kb my host rejects it and I am diverted to a page that says "The connection to the server was reset while the page was loading." so no more php is executed.

You can have a look at my test page at http://www.getoutofglasgow.com/Trip10.htm and use the logon "tester" with the password "test".

The max upload file size is set using the ini_set to 100Kb so try a file less than this, one of 100Kb to 499Kb and one of over 500Kb and you'll see what the problem is.

Posted: Sun Dec 16, 2007 11:51 am
by John Cartwright
Jcart wrote:
mikeym wrote:I was thinking of something more like

Code: Select all

<input type="file" name="file" accept="image/jpeg" maxlength="500000" />
as I don't host my own site. Unfortunately at least Firefox doesn't support this method. Is there anyway to get something better than a page not found error if someone tries a file over 500Kb. Perhaps I could check the file locally using Javascript???? It doesn't have to be secure because they can't load it up anyway!
I hate this method, and it can NEVER be relied on. Javascript is not an option here in this case since it does not have access to the users filesystem.

Have you tried anjanesh's suggestion?
For some reason I thought this was the same as setting the hidden field of MAX_FILE_SIZE

Go ahead and remove this line from your form

Code: Select all

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

Posted: Sun Dec 16, 2007 11:53 am
by anjanesh
I tried uploading a file of 44KB and I got

Code: Select all

Warning: MAX_FILE_SIZE of 100 bytes exceeded - file [file=image.gif] not saved in Unknown on line 0

Warning: session_start(): Cannot send session cache limiter - headers already sent in /home/www/getoutofglasgow.com/include/session.php on line 47
Error extension =
Warning: unlink(): No such file or directory in /home/www/getoutofglasgow.com/include/images.php on line 82
Tried uploading a 314Kb jpg, but its getting time out (The connection was reset).

Btw, since you're into this uploading part, check how flickr uploads - I dont know if its ajax or a firefox addon (cant seem to remember installing one), but it uploads with a progress bar and not using the traditional upload technique.

Posted: Sun Dec 16, 2007 12:34 pm
by mikeym
Sorry you must have had a look at the page when I was trying something else.

Code: Select all

<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Makes no difference to the phenomenon I was talking about. The real issue is for files over 500Kb the rest works how it should - ie creates a php error which I can correct. I will have a look at flicker.