Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old June 28th, 2005, 08:52 PM
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:

<?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
?>
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 06:07 AM
Guidelines Item 3: Replace System.Type with Type Ixtlia BOOK: Professional .NET 2.0 Generics 0 August 19th, 2007 05:09 AM
Ch. 4 & Ch. 12 athena BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 0 July 23rd, 2004 11:54 AM
Data Type error but it is the correct type Mitch SQL Server 2000 2 March 19th, 2004 11:31 AM



All times are GMT -4. The time now is 10:03 PM.


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