470,833 Members | 1,397 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,833 developers. It's quick & easy.

upload images

Hi,

I am not an experienced PHP programmer and have look on the net for
what I want to do.

I'd like to allow the user on my website to upload two images one is to
be turned into a thumbnail and one is to be turned into something of
around 500 x 300, one stored in a thumbnail folder and one stored in an
image folder.

I can do it individually from different pages but not from the same
form.

Could someone point me in the direction of a script that does something
like what I am after.

Many thanks
Darren

Feb 9 '06 #1
3 1371
Hi Darren,

why do you need two forms??

you just need one form with one <INPUT TYPE='file' NAME='upfile'...
(the user selects his image with this input field)
then post the form....
after it you get your file with $_FILES[ upfile ]...
http://at.php.net/features.file-upload

then process $_FILES[ upfile ][ tmp_name ]:

for your main graphic create a new image with: $bigImage =
imagecreate($newWidth, $newHeight);
in your case $newWidth must be 500; $newHeight = 300

$origImage = imagecreatefrom*( $_FILES[ upfile ][ tmp_name] );
Notice: * depends on filetype: e.g. jpg, gif, png --> have a look on
php.net: imagecreatefromjpeg

to get the original height and width you need the getimagesize command:
$infos = getimagesize($_FILES[ upfile ][ tmp_name ]);
$origWidth = $infos[0];
$origHeight = $infos[1];

imagecopyresampled($bigImage, $origImage, 0, 0, 0, 0, $newWidth,
$newHeight, $origWidth, $origHeight);
image*($bigImage,"/image/filename.*");
Notice: * depends on filetype: e.g. jpg, gif, png --> have a look on
php.net: e.g. imagegif

just do the same for your thumbs (you just want a smaller
$newWith/$newHeight):
imagecopyresampled($thumbImage, $origImage, 0, 0, 0, 0, $newWidth,
$newHeight, $origWidth, $origHeight);
image*($thumbImage,"/tmb/filename.*");

regards
flo

Feb 9 '06 #2
Thanks Flo,

Feb 9 '06 #3
"Darren" <gr****@darrenludlam.plus.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
Hi,

I am not an experienced PHP programmer and have look on the net for
what I want to do.

I'd like to allow the user on my website to upload two images one is to
be turned into a thumbnail and one is to be turned into something of
around 500 x 300, one stored in a thumbnail folder and one stored in an
image folder.

I can do it individually from different pages but not from the same
form.

Could someone point me in the direction of a script that does something
like what I am after.

Many thanks
Darren


check out this php class:
http://www.phpclasses.org/browse/file/9056.html

you'll need to register to download it, but it's a great toolset for working
with images (resizing, copying, etc.)

- kevin
Feb 10 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by dave | last post: by
4 posts views Thread by NohaKhalifa | last post: by
2 posts views Thread by Tom Wells | last post: by
1 post views Thread by BW | last post: by
3 posts views Thread by Pitcairnia | last post: by
reply views Thread by SEMIH DEMIR | last post: by
9 posts views Thread by Wayne Smith | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.