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:

//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

All times are GMT -4. The time now is 06:04 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.