Jump to content

Archived

This topic is now archived and is closed to further replies.

benwhitmore

Verify image dimensions befor it is uploaded

Recommended Posts

Hi peeps,

When I add a record to my database, I also have the option to upload an image associated with that record.

How can I verify the images' size befor I upload it. Basically, the image must be less than 400px high or wide.

Any feedback welcome
Thanks

Share this post


Link to post
Share on other sites
That's simple - you can't determine an image's size unless you have already uploaded it.

You have these choices:

Upload the image and if it's oversized do not add image data to the database. The uploaded image can be left in the tmp folder which empties itself at the end of a browser session.

Upload the image and re-size it so its dimensions suit your requirements, then save the image and image data.

Share this post


Link to post
Share on other sites
great, thanks for the heads up.

it works now, i done it this way incase anyone was wondering....

[code]
foreach($_FILES as $image=>$image_array){
if (is_uploaded_file($image_array['tmp_name'])){

list($width_orig, $height_orig) = getimagesize($image_array['tmp_name']);

if ($width_orig>400 || $height_orig>400){
echo "That is too big my friend, choose a pic smaller than 400px wide or 400px high";
}

}
}
[/code]

thanks again

SOLVED

Share this post


Link to post
Share on other sites
[!--quoteo(post=377846:date=May 28 2006, 10:11 AM:name=AndyB)--][div class=\'quotetop\']QUOTE(AndyB @ May 28 2006, 10:11 AM) [snapback]377846[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Upload the image and re-size it so its dimensions suit your requirements, then save the image and image data.
[/quote]

Just wondering, but how do you change the size of an image once it has been uploaded?

Share this post


Link to post
Share on other sites
[a href=\"http://uk2.php.net/manual/en/function.imagecopyresized.php\" target=\"_blank\"]http://uk2.php.net/manual/en/function.imagecopyresized.php[/a]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.