View Single Post
  #1 (permalink)  
Old June 28th, 2005, 07:52 PM
drichard drichard is offline
Registered User
Join Date: Jun 2005
Location: Lancaster, PA, USA.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default $type determination (CH 7)

I am having trouble retrieving the $type variable in the check_image.php code starting on page 203. The previous check_image example starting on page 197 worked well.

It appears that the code starting on page 203 probably returns a null for $type. When I try to echo the $type variable, I get no response. The program does not distinguish between gif, jpg and bmp.

Any suggestions would be more then welcome.

Here is the code for check_image.php as I have it:

//connect to the database

$link = mysql_connect("localhost", "drichard", "drichard")
        or die("Could not connect: " . mysql_error());
    mysql_select_db('moviesite', $link)
        or die(mysql_error());

//make variables available
$today = date("Y-m-d");

//upload image and check for image type
//make sure to change your path to match your images directory


$ImageName=$ImageDir . $image_tempname;

if(move_uploaded_file($_FILES['image_filename']['tmp_name'],$ImageName)) {
  //get info about file being uploaded
  list($width, $height, $type, $attr) = getimagesize($ImageName);

IF ($type > 3) {
        echo "Sorry, but the file you uploaded was not a GIF, JPG, or PNG file.<br>";
        echo "Please hit your browser's back button and try again.";
    } else {
        //image is acceptable; ok to proceed

  //insert info into image table
  $insert="INSERT INTO images
            (image_caption, image_username, image_date)
            ('$image_caption', '$image_username', '$today')";
  $insertresults = mysql_query($insert)
        or die(mysql_error());
  $lastpicid = mysql_insert_id();

  $newfilename = $ImageDir . $lastpicid . ".jpg";
    if ($type==2) {
      rename($ImageName, $newfilename);
      } else {
        if ($type == 1) {
        $image_old = imagecreatefromgif($ImageName);
        } elseif ($type == 3) {
        $imageold = imagecreatefrompng($ImageName);
      //"convert" the image to jpg
      $image_jpg = imagecreatetruecolor($width, $height);
      imagecopyresampled($image_jpg, $image_old, 0, 0, 0, 0, $width, $height, $width, $height);
      imagejpeg($image_jpg, $newfilename);

    $url = "location: showimage.php?id=" . $lastpicid;

} else { //close from Line 23 - if(move)
  echo "download failure";
}//close from Line 23 - if(move) failure