Ok,
I have been looking around and I found this: http://www.theopensurgery.com/29/php-upload-and-resize-image-script/ -- which I have and its working great. Basically it uploads an image and then creates the thumbnail. I am using the previous code (in my original post) to display those thumbnails -- which is also working great. Now what I need to figure out is how to take those thumbnails and link them to the larger image. Any ideas? I have attached the code I am using below.
Page displaying the thumbnails:
<?php
//displays images from our directory
$handle = opendir ('./images/thumbnails');
while (false !== ($file = readdir($handle))) {
if($file != "." && $file != ".." && $file != basename(__FILE__)) {
echo '<img src="./images/thumbnails/'.$file.'"/><br /><br />';
}
}
?>
Upload script creating/uploading the thumbnails:
<form action="<?php echo $_server['php-self']; ?>" method="post" enctype="multipart/form-data" id="something" class="uniForm">
<input name="new_image" id="new_image" size="30" type="file" class="fileUpload" />
<button name="submit" type="submit" class="submitButton">Upload/Resize Image</button>
</form>
<?php
if(isset($_POST['submit'])){
if (isset ($_FILES['new_image'])){
$imagename = $_FILES['new_image']['name'];
$source = $_FILES['new_image']['tmp_name'];
$target = "images/".$imagename;
move_uploaded_file($source, $target);
$imagepath = $imagename;
$save = "images/" . $imagepath; //This is the new file you saving
$file = "images/" . $imagepath; //This is the original file
list($width, $height) = getimagesize($file) ;
$modwidth = 600;
$diff = $width / $modwidth;
$modheight = $height / $diff;
$tn = imagecreatetruecolor($modwidth, $modheight) ;
$image = imagecreatefromjpeg($file) ;
imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ;
imagejpeg($tn, $save, 100) ;
$save = "images/thumbnails/sml_" . $imagepath; //This is the new file you saving
$file = "images/" . $imagepath; //This is the original file
list($width, $height) = getimagesize($file) ;
$modwidth = 100;
$diff = $width / $modwidth;
$modheight = $height / $diff;
$tn = imagecreatetruecolor($modwidth, $modheight) ;
$image = imagecreatefromjpeg($file) ;
imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ;
imagejpeg($tn, $save, 100) ;
echo "Large image: <img src='images/".$imagepath."'><br>";
echo "Thumbnail: <img src='images/thumbnails/sml_".$imagepath."'>";
}
}
?>
Thanks,
Josh