samoht Posted August 30, 2007 Share Posted August 30, 2007 hello again, I have almost got everything working the way that I want it. I can upload a picture and save a thumbnail - both with the proper names. I would like to be able to add another thumbnail but larger this time. So in total I would save and upload 3 pictures all with different widths. Here is the function to upload the images: <?php function uploadProductImage($inputName, $uploadDir) { $image = $_FILES[$inputName]; $ItemId = (int)$_GET['ItemId']; $imagePath = ''; $thumbnailPath = ''; // if a file is given if (trim($image['tmp_name']) != '') { $ext = substr(strrchr($image['name'], "."), 1); //$extensions[$image['type']]; // generate a new file name to avoid name conflict - this is where I want to add ls $q = "SELECT b.Code FROM item i, brands b WHERE i.ItemId = $ItemId AND i.BrandId = b. BrandId"; $result = mysql_query($q); $row = mysql_fetch_assoc($result); extract($row); $imagePath = $Code."-".$ItemId."ls" . ".$ext"; list($width, $height, $type, $attr) = getimagesize($image['tmp_name']); // make sure the image width does not exceed the // maximum allowed width if ($width > 120) { $result = createThumbnail($image['tmp_name'], $uploadDir . $imagePath, 120); $imagePath = $result; } else { $result = move_uploaded_file($image['tmp_name'], $uploadDir . $imagePath); } if ($result) { // create thumbnail $thumbnailPath = $Code."-".$ItemId."tn" . ".$ext"; $result = createThumbnail($uploadDir . $imagePath, $uploadDir . $thumbnailPath, 96); // if create thumbnail failed, delete the image if (!$result) { unlink($uploadDir . $imagePath); $imagePath = $thumbnailPath = ''; } else { $thumbnailPath = $result; } } else { // the product cannot be upload / resized $imagePath = $thumbnailPath = ''; } } return array('image' => $imagePath, 'thumbnail' => $thumbnailPath); } and here is the create thumb function - I also have a create full size function which is exactly the same but the name and quality are changed <?php function createThumbnail($srcFile, $destFile, $width, $quality = 96) { $thumbnail = ''; if (file_exists($srcFile) && isset($destFile)) { $size = getimagesize($srcFile); $w = number_format($width, 0, ',', ''); $h = number_format(($size[1] / $size[0]) * $width, 0, ',', ''); $thumbnail = copyImage($srcFile, $destFile, $w, $h, $quality); } // return the thumbnail file name on sucess or blank on fail return basename($thumbnail); } any one have ideas how I can add the createfullsize function to the upload ?? Thanks, is that enough info? Link to comment https://forums.phpfreaks.com/topic/67361-help-with-two-image-save/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.