Jump to content


Photo

Verify image dimensions befor it is uploaded


  • Please log in to reply
4 replies to this topic

#1 benwhitmore

benwhitmore
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 28 May 2006 - 03:03 PM

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

#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 28 May 2006 - 03:11 PM

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.
Legend has it that reading the manual never killed anyone.
My site

#3 benwhitmore

benwhitmore
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 28 May 2006 - 04:01 PM

great, thanks for the heads up.

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

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";
}

}
}

thanks again

SOLVED

#4 thehigherentity

thehigherentity
  • Members
  • PipPipPip
  • Advanced Member
  • 49 posts

Posted 29 May 2006 - 09:10 AM

[!--quoteo(post=377846:date=May 28 2006, 10:11 AM:name=AndyB)--][div class=\'quotetop\']QUOTE(AndyB @ May 28 2006, 10:11 AM) View Post[/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?

The best way to learn
is to ask you lot........

#5 GingerRobot

GingerRobot
  • Staff Alumni
  • Advanced Member
  • 4,086 posts
  • LocationUK

Posted 29 May 2006 - 09:14 AM

[a href=\"http://uk2.php.net/manual/en/function.imagecopyresized.php\" target=\"_blank\"]http://uk2.php.net/manual/en/function.imagecopyresized.php[/a]




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users