Jump to content

Recommended Posts

hi there i am working on a gallery where you can upload a image and it will create a thumb nail. the problem is that is says that it has been entered in to the directory bub when i try to view the image the large image appears and the thumb just comes up as text.....

 

i thought about this so i copied the big image and placed it in the thumbs folder and reloaded the web page and there was the thumb nail. so i guessing its a directory problem but i can't see it... is there any chance you bright people of the php world can help

 

<?php
  define('THUMBS_DIR', 'c:/test/images/thumbs/');
  define('MAX_WIDTH', 200);
  define('MAX_HEIGHT', 150);
    
// process the uploaded image
  if (is_uploaded_file($_FILES['image']['tmp_name'])) {
    $original = $_FILES['image']['tmp_name'];
    // begin by getting the details of the origin<a href="create_thumb.php">Create thumbnail image</a>al
    list($width, $height, $type) = getimagesize($original);
// calculate the scaling ratio
    if ($width <= MAX_WIDTH && $height <= MAX_HEIGHT) {
      $ratio = 1;
      }
    elseif ($width > $height) {
      $ratio = MAX_WIDTH/$width;
      }
    else {
      $ratio = MAX_HEIGHT/$height;
      }
// strip the extension off the image filename
$imagetypes = array('/\.gif$/', '/\.jpg$/', '/\.jpeg$/', '/\.png$/');
    $name = preg_replace($imagetypes, '', basename($_FILES['image']['name']));

    // move the temporary file to the upload folder
$moved = move_uploaded_file($original, UPLOAD_DIR.$_FILES['image']['name']);
if ($moved) {
  $result = $_FILES['image']['name'].' successfully uploaded; ';
  $original = UPLOAD_DIR.$_FILES['image']['name'];
  }
else {
  $result = 'Problem uploading '.$_FILES['image']['name'].'; ';
  }

// create an image resource for the original
switch($type) {
      case 1:
        $source = @ imagecreatefromgif($original);
    if (!$source) {
      $result = 'Cannot process GIF files. Please use JPEG or PNG.';
      }
    break;
      case 2:
        $source = imagecreatefromjpeg($original);
    break;
      case 3:
        $source = imagecreatefrompng($original);
    break;
      default:
        $source = NULL;
    $result = 'Cannot identify file type.';
      }
// make sure the image resource is OK
if (!$source) {
  $result = 'Problem copying original';
  }
else {
  // calculate the dimensions of the thumbnail
      $thumb_width = round($width * $ratio);
      $thumb_height = round($height * $ratio);
  // create an image resource for the thumbnail
      $thumb = imagecreatetruecolor($thumb_width, $thumb_height);
  // create the resized copy
  imagecopyresampled($thumb, $source, 0, 0, 0, 0, $thumb_width, $thumb_height, $width, $height);
  // save the resized copy
  switch($type) {
        case 1:
      if (function_exists('imagegif')) {
        $success = imagegif($thumb, THUMBS_DIR.$name.'_thb.gif');
        $thumb_name = $name.'_thb.gif';
	    }
      else {
        $success = imagejpeg($thumb, THUMBS_DIR.$name.'_thb.jpg', 50);
	    $thumb_name = $name.'_thb.jpg';
	    }
      break;
    case 2:
      $success = imagejpeg($thumb, THUMBS_DIR.$name.'_thb.jpg', 100);
      $thumb_name = $name.'_thb.jpg';
      break;
    case 3:
      $success = imagepng($thumb, THUMBS_DIR.$name.'_thb.png');
      $thumb_name = $name.'_thb.png';
    }
	if ($success) {
	   $result .= "$thumb_name created";
	  include('insert_test.php');
	  }
	else {
	  $result .= 'Problem creating thumbnail';
	  }
  // remove the image resources from memory
  imagedestroy($source);
      imagedestroy($thumb);
  }
}
?>

 

all help and comments are helpful thanks

Link to comment
https://forums.phpfreaks.com/topic/52136-gallery-probs/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.