how to limit uploads to: JPG only, max 3 files, max 300kb/file each

See all posts Reply

how to limit uploads to: JPG only, max 3 files, max 300kb/file each new!
by timid-php-beginner, 16 years, 3 months ago
How to customize the code, in order to achieve these results:

Conditions:
-file_type=only JPG files are allowed for upload
-file_number=maximum 3 files are allowed for upload
(I'll set this on html-form, by adding just 3 input fields,ain't that?)
-file_size=maximum 300 KB allowed for each file
-file_image_width=maximum 640 px allowed

if above conditions not respected than...
write some alert text and do some actions(???):

-file_type=must be JPG
-file_size=must be maximum 300 KB
-file_image_width=must be maximum 640 px

if all conditions respected than...
upload these files to /my server/folder
and save themReply
Re: how to limit uploads to: JPG only, max 3 files, max 300kb/file each new!
by colin, 16 years, 3 months ago
So... First, your code will have to handle the form, the alert messages, etc...

You will put three fields in the form. In that case, you will have to tramsform a bit your $_FILES variable. See the faq for multiple uploads.

As for the class, here are the settings that should satisfy your requirements:
$foo->allowed = array('image/*');
$foo->image_convert = 'jpg';

Then, to forbid images larger than 640px wide, add:
$foo->image_max_width = 640;
$foo->file_max_size = 300 * 1024;

But you can also simply resize all images larger than 640px, so add instead:
$foo->image_resize = true;
$foo->image_ratio_no_zoom_in = true;
$foo->image_x = 640;
$foo->jpeg_size = 300 * 1024;

Hope this helps. The rest will be for you to figure out, it is beyond the scope of the class.Reply
Re: how to limit uploads to: JPG only, max 3 files, max 300kb/file each new!
by timid-php-beginner, 16 years, 3 months ago
Thank you very much. It's just what I needed. I will manage the rest of changes with the help from faq and docs.Reply