Wrox Programmer Forums
BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0
This is the forum to discuss the Wrox book Beginning PHP5, Apache, and MySQL Web Development by Elizabeth Naramore, Jason Gerner, Yann Le Scouarnec, Jeremy Stolz, Michael K. Glass; ISBN: 9780764579660
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old June 28th, 2005, 07:52 PM
Registered User
Join Date: Jun 2005
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

Similar Threads
Thread Thread Starter Forum Replies Last Post
DataRowView Type Not Defined (CH 14) kmwilliams5 ASP.NET 3.5 Basics 5 April 25th, 2009 05:07 AM
Guidelines Item 3: Replace System.Type with Type Ixtlia BOOK: Professional .NET 2.0 Generics 0 August 19th, 2007 04:09 AM
Ch. 4 & Ch. 12 athena BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 0 July 23rd, 2004 10:54 AM
Data Type error but it is the correct type Mitch SQL Server 2000 2 March 19th, 2004 11:31 AM

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