p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 (http://p2p.wrox.com/forumdisplay.php?f=160)
-   -   $type determination (CH 7) (http://p2p.wrox.com/showthread.php?t=30952)

drichard June 28th, 2005 07:52 PM

$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:

<?php
//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
$image_caption=$_POST['image_caption'];
$image_username=$_POST['image_username'];
$image_tempname=$_FILES['image_filename']['name'];
$today = date("Y-m-d");

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

$ImageDir="D:/webroot/images/";

$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)
            VALUES
            ('$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);
      imagedestroy($image_old);
      imagedestroy($image_jpg);
        }

    $url = "location: showimage.php?id=" . $lastpicid;
    header($url);
 }

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


All times are GMT -4. The time now is 07:52 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.