Image management - limit file size

A place to discuss and receive support for the Web Auction application.

Image management - limit file size

Postby bobede » Fri May 23, 2008 7:22 am

Can the upload file size of product_image be limited. I had some users that were not following my advice about optimizing images and were uploading files in excess of 3mb. I would like to force them to comply.
bobede
 
Posts: 24
Joined: Tue Oct 30, 2007 7:01 am

Postby shannah » Fri May 23, 2008 10:14 am

In the tables/products/fields.ini file find the section pertaining to the product_image field:
Code: Select all
[product_image]
Type=container
allowed_extensions="jpg,gif,png"
visibility:list = hidden
visibility:list = hidden


Add the maxfilesize validator to this section. E.g.:

Code: Select all
validators:maxfilesize = 32000


This would limit the upload size to 32k (i.e. the size is specified in bytes).

The user would then get an error message saying that the product_image field had illegal input. You may want to provide your own custom error message for this case to make it more clear that the problem was that the file was too big. In this case you could add:

Code: Select all
validators:maxfilesize:message = "The file you uploaded was too big!!"


So when you're done, the product_image section might look something like:

Code: Select all
[product_image]
Type=container
allowed_extensions="jpg,gif,png"
visibility:list = hidden
visibility:list = hidden
validators:maxfilesize = 32000
validators:maxfilesize:message = "The file you uploaded is too big!!"



On some of my sites I have integrated an image server script to automatically shrink images to avoid this problem... but I'll save that for another post.



Best regards

Steve
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby bobede » Fri May 23, 2008 6:07 pm

Perfect.

Thanks Steve
bobede
 
Posts: 24
Joined: Tue Oct 30, 2007 7:01 am


Return to Web Auction Discussion

Who is online

Users browsing this forum: No registered users and 22 guests

Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved