Image size restrictions
Moderator: General Moderators
Image size restrictions
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?
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?
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 ...
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');I was thinking of something more like
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!
Code: Select all
<input type="file" name="file" accept="image/jpeg" maxlength="500000" />- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
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.mikeym wrote:I was thinking of something more like
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!Code: Select all
<input type="file" name="file" accept="image/jpeg" maxlength="500000" />
Have you tried anjanesh's suggestion?
Also try creating a .htaccess file in your main folder and have this text in that file:
You may need to verify the attribute names.
Code: Select all
php_value upload_max_filesize 10M
php_value post_max_size 20MThis 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.
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.
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
For some reason I thought this was the same as setting the hidden field of MAX_FILE_SIZEJcart wrote: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.mikeym wrote:I was thinking of something more like
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!Code: Select all
<input type="file" name="file" accept="image/jpeg" maxlength="500000" />
Have you tried anjanesh's suggestion?
Go ahead and remove this line from your form
Code: Select all
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />I tried uploading a file of 44KB and I got
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.
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 82Btw, 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.
Sorry you must have had a look at the page when I was trying something else.
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.
Code: Select all
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />