Page 1 of 1

can't get rid of temp image

Posted: 2007-11-25T10:18:42-07:00
by chopthewood
I have the following php script which works well except that a copy of the uploaded image always gets placed in the "php" directory as well as the two other specified locations (largeImages and thumbImages). How can I avoid this?
thanks

Code: Select all

<HTML>
<HEAD>
<TITLE>Successful File Upload</TITLE>
</HEAD>

<BODY>

<?


$largeImgName=$_FILES['imgLarge']['name'];

$thumbImgName=$largeImgName;
//

//

// ------------------------ IMAGE MAGICK ---------------------------



// Temporary upload image names
$originalLarge_image = $_FILES[imgLarge][tmp_name];
$originalThumb_image=$_FILES[imgLarge][tmp_name];
// set the jpg quality
$theQualityLarge=75;
$theQualityThumb=60;
// Get the image dimensions
$sizeLarge=GetImageSize( $originalLarge_image );
$sizeThumb=GetImageSize( $originalLarge_image );

// Maximum image width
$max_widthLarge = "450";
$max_widthThumb = "100";

// Maximum image height
$max_heightLarge = "450";
$max_widthThumb = "100";
//
// Resize the image and save


exec("convert -size {$sizeThumb[0]}x{$sizeThumb[1]}  $originalThumb_image -thumbnail {$max_widthThumb}x{$max_heightThumb} -quality $theQualityThumb $thumbImgName");
@copy( $originalThumb_image,"/home/jmt/public_html/thumbImages/".$thumbImgName) or die("Couldn't copy the Large image.");

exec("convert -size {$sizeLarge[0]}x{$sizeLarge[1]}  $originalLarge_image -thumbnail {$max_widthLarge}x{$max_heightLarge} -quality $theQualityLarge $largeImgName");
@copy($originalLarge_image,"/home/jmt/public_html/largeImages/".$largeImgName) or die("Couldn't copy the Large image.");


echo "<img src=\"".$largeImgName."\">";


?>


<H1>Success!</H1>

<P>You have uploaded the image: <b><? echo $_FILES[imgLarge][name]; ?>,</b> to your portfolio site.<br>
If you haven't already done so, be sure to create an information file about this artwork.


</BODY>
</HTML>

Re: can't get rid of temp image

Posted: 2007-11-25T15:03:30-07:00
by Bonzo
I presume as you are saving the image with ImageMagick then copying it that is the problem.

I would either unlink( ) the image created, use move instead of copy or preferably save directly to the finished destination folder.

Re: can't get rid of temp image

Posted: 2007-11-25T16:19:18-07:00
by chopthewood
I'm using the @copy to copy directly to the destination directory. I don't know why it's also being copied to the php folder.

Re: can't get rid of temp image

Posted: 2007-11-26T03:33:27-07:00
by Bonzo
What I am saying is why save the image and then copy it ? You should be able to save it directly to the final folder. This will remove one step as well.

Code: Select all

exec("convert -size {$sizeThumb[0]}x{$sizeThumb[1]}  $originalThumb_image -thumbnail {$max_widthThumb}x{$max_heightThumb} -quality $theQualityThumb /home/jmt/public_html/thumbImages/$thumbImgName");

exec("convert -size {$sizeLarge[0]}x{$sizeLarge[1]}  $originalLarge_image -thumbnail {$max_widthLarge}x{$max_heightLarge} -quality $theQualityLarge /home/jmt/public_html/largeImages/$largeImgName");

Re: can't get rid of temp image

Posted: 2007-11-26T10:11:07-07:00
by chopthewood
thank you again, Bonzo. What I didn't realize was that within the "exec" parameters, the image was actually being saved to the server (there doesn't seem to be a 'save' command of any kind in there). I thought that it was simply resizing it and setting the quality, then I needed to @copy it after that. I am totally unfamiliar with command line stuff.
Anyway, that worked great and I appreciate this forum and others like it. They are so valuable to programmers of all levels.

:D

Re: can't get rid of temp image

Posted: 2007-11-26T12:49:53-07:00
by Bonzo
I am glad its sorted now; I did wonder why you insisted on using the @copy !

The trouble is I tend to forget the basics and think things like that are obvious.