Jump to content


Photo

Need Help Uploading Images...


  • Please log in to reply
3 replies to this topic

#1 CSmith1128

CSmith1128
  • Members
  • PipPipPip
  • Advanced Member
  • 46 posts

Posted 23 May 2006 - 03:01 AM

[!--fonto:Tahoma--][span style=\"font-family:Tahoma\"][!--/fonto--]Hello.. I need some help uploading images...

First, I would like to have a page where a user can upload multiple images from 1 place (up to 3 images). So I would like to have 3 browse fields on the page and when they click submit they will be uploaded.

Next, I would like to resize EACH image to 4 different sizes, then store each one in a different folder. I do not need to store the original image, only the resized images.

And I need each image to be resized so they are not blurry or distorted. So I need an image to be 100 pixels x 80 pixels. The image can be smaller if it needs to be so it won't be distorted, but it cannot be any larger.

Could someone help me with this? :-)

Thank you,
Chris [!--fontc--][/span][!--/fontc--]

#2 michaellunsford

michaellunsford
  • Members
  • PipPipPip
  • Advanced Member
  • 1,023 posts
  • LocationLouisiana, USA

Posted 23 May 2006 - 04:24 AM

A few manual pages to get started on:

[a href=\"http://www.php.net/features.file-upload\" target=\"_blank\"]http://www.php.net/features.file-upload[/a]

[a href=\"http://www.php.net/imagecreatefromstring\" target=\"_blank\"]http://www.php.net/imagecreatefromstring[/a]

[a href=\"http://www.php.net/imagecopyresampled\" target=\"_blank\"]http://www.php.net/imagecopyresampled[/a]

fundamentals: you can use imagecreatefromstring(file_get_contents($_FILES[key($_FILES)]['tmp_name'])) to create images from uploaded files. You can loop through multiple uploaded files by enclosing it in a while(next($_FILES)) loop.

once you've created the image, you'll need to resize it if it's larger than your current image, so you'll have to verify image dimentions... You can find the width and height of created image using imagesx() and imagesy() respectively.

the math for resizing images gets tricky. here's an example of landscape orentation:
$im=imagecreatefromstring(file_get_contents($_FILES[key($_FILES)]['tmp_name']));
$newim=imagecreatetruecolor($width,((imagesy($im)/imagesx($im))*$max_width));
imagecopyresampled($newim,$im,0,0,0,0,$max_width,((imagesy($im)/imagesx($im))*$max_width),imagesx($im),imagesy($im));
and portrait orentation:
$im=imagecreatefromstring(file_get_contents($_FILES[key($_FILES)]['tmp_name']));
$newim=imagecreatetruecolor(((imagesx($im)/imagesy($im))*$max_height),$max_height);
imagecopyresampled($newim,$im,0,0,0,0,((imagesx($im)/imagesy($im))*$max_height),$max_height,imagesx($im),imagesy($im));

you can find the image orentation by comparing imagesx to imagesy.

you can save images using somthing like imagejpeg(), imagepng(), imagegif(), etc.

hope that helps

#3 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 23 May 2006 - 04:50 AM

A quick quistion michaellunsford afther an image is resampled to
the size does the oreginal get placed in the same folder cheers.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#4 michaellunsford

michaellunsford
  • Members
  • PipPipPip
  • Advanced Member
  • 1,023 posts
  • LocationLouisiana, USA

Posted 23 May 2006 - 05:00 AM

the original uploaded file is located in your /tmp/ directory (most likely) and will be deleted by the system eventually. In order to save a file someplace that won't be deleted, you have to copy or move it yourself. you can use move_uploaded_file(), or (since you have created and resized an image using PHP) you can save the image using imagejpeg (or any of the other image save functions).

again, the original uploaded image should eventually be deleted by the system.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users