I'm having a problem displaying multiple images using the following script. I don't want to create thumbnail files since there are a low number of hits and I don't want to have to remind the user to remove a thumbnail when they delete the original.
If I send one file name to thumbnail.php, it works fine. If I send a second, third, etc... file name I end up with multiple thumbnails of the last file passed.
How do I create the thumbnails so that they don't stomp on each other?
<?php
session_start();
echo "<html><head></head><body><h2>My Picture Test</H2>";
$HTTP_SESSION_VARS['sf'] = "red.jpg";
echo "<img src='thumbnail.php'>";
$HTTP_SESSION_VARS['sf'] = "green.jpg";
echo "<img src='thumbnail.php'>";
echo "</body></html>";
?>
--thumbnail.php--
<?php
session_start();
$sourcefile= $HTTP_SESSION_VARS['sf'];
$picsize=getimagesize("$sourcefile");
$source_x = $picsize[0];
$source_y = $picsize[1];
$x_ratio = ($source_x/100);
if($x_ratio > 1)
{
$x = round($source_x/$x_ratio);
$y = round($source_y/$x_ratio);
}
else
{
$x = $picsize[0];
$y = $picsize[1];
}
$source_id = imageCreateFromJPEG("$sourcefile");
$target_id=imagecreatetruecolor($x, $y);
/ Resize the original picture and copy it into the just created image object./
$target=imagecopyresampled($target_id,$source_id, 0, 0 , 0 , 0, $x, $y, $source_x, $source_y);
Header("Content-type: image/jpeg");
ob_start();
imagejpeg ($target_id, "", "50");
$HTTP_SESSION_VARS['$sourcefile'] = ob_get_contents();
ob_end_clean();
echo $HTTP_SESSION_VARS['$sourcefile'];
?>