Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| 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 Search this Thread Display Modes
  #1 (permalink)  
Old November 10th, 2006, 04:32 PM
Authorized User
 
Join Date: Mar 2005
Location: arima, West Indies, Trinidad and Tobago.
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to arimakidd
Default That Infamous Chapter 7

Everyone seems to be having a problem with chapter 7 one way or the other. My local installation is set up fine and the main images are going to the images folder just fine, my problem is the thumbnails folder. Nothing is going to the thumbnails folder. I decided to check the check_image.php file and my debugging technique is one where I simply echo out some text and then exit so the rest of the script so that it doesn't execute. Using this method, the only part of the script that doesn't execute the echo command is the part that re-sizes the original image to the thumbnail and then sends the thumbnail to the thumbnails folder. I really do hope I can get some help here. This is the entire script:
Code:
<?php

//connect to the database
$link = mysql_connect("localhost", "root", "newman$")
  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
$ImageDir ="C:/apache/Apache2/htdocs/test/images/";

//**INSERT THIS LINE:
$ImageThumb = $ImageDir . "thumbs/";
//**END OF INSERT

$ImageName = $ImageDir . $image_tempname;

if (move_uploaded_file($_FILES['image_filename']['tmp_name'], 
                      $ImageName)) {

  //get info about the image being uploaded
  list($width, $height, $type, $attr) = getimagesize($ImageName);

  //**delete these lines
  switch ($type) {
    case 1:
      $ext = ".gif";
      break;
    case 2:
      $ext = ".jpg";
      break;
    case 3:
      $ext = ".png";
      break;
    default:
      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.";
  }
  //**end of deleted lines

  //**insert these new lines
  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

  //**end of inserted lines

  //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();


  //change the following line:
  $newfilename =  $ImageDir . $lastpicid . ".jpg";

  //**insert these lines
 if ($type == 2) {
    rename($ImageName, $newfilename);
  } elseif ($type == 1) {
      $image_old = imagecreatefromgif($ImageName);
  } elseif ($type == 3) {
      $image_old = imagecreatefrompng($ImageName);
  }
    $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);
  }
  }

//**INSERT THESE LINES

  $newthumbname = $ImageThumb . $lastpicid . ".jpg";

  //get the dimensions for the thumbnail
  $thumb_width = $width * 0.10;
  $thumb_height = $height * 0.10;


  //create the thumbnail
  $largeimage = imagecreatefromjpeg($newfilename);
  $thumb = imagecreatetruecolor($thumb_width, $thumb_height);
  imagecopyresampled($thumb, $largeimage, 0, 0, 0, 0, 
                    $thumb_width, $thumb_height, $width, $height);
  imagejpeg($thumb, $newthumbname);
  imagedestroy($largeimage);
  imagedestroy($thumb);
//**END OF INSERT
echo "good up to here";
exit();

  $url = "location: showimage.php?id=" . $lastpicid;
  header($url);
  //**end of inserted lines
}

?>
This is the part that doesn't echo out my debugging technique.

Code:
 if ($type == 2) {
    rename($ImageName, $newfilename);
  } elseif ($type == 1) {
      $image_old = imagecreatefromgif($ImageName);
  } elseif ($type == 3) {
      $image_old = imagecreatefrompng($ImageName);
  }
    $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);
  }


//**INSERT THESE LINES

  $newthumbname = $ImageThumb . $lastpicid . ".jpg";

  //get the dimensions for the thumbnail
  $thumb_width = $width * 0.10;
  $thumb_height = $height * 0.10;


  //create the thumbnail
  $largeimage = imagecreatefromjpeg($newfilename);
  $thumb = imagecreatetruecolor($thumb_width, $thumb_height);
  imagecopyresampled($thumb, $largeimage, 0, 0, 0, 0, 
                    $thumb_width, $thumb_height, $width, $height);
  imagejpeg($thumb, $newthumbname);
  imagedestroy($largeimage);
  imagedestroy($thumb);
//**END OF INSERT
echo "good up to here";
exit();

  $url = "location: showimage.php?id=" . $lastpicid;
  header($url);
  //**end of inserted lines
}
I do really hope I can get some help.

Reply With Quote
  #2 (permalink)  
Old November 17th, 2006, 08:02 AM
Authorized User
 
Join Date: Mar 2005
Location: arima, West Indies, Trinidad and Tobago.
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to arimakidd
Default

This problem has been solved. It works now, the thumbnails go to the thumbnail folder and the original image goes to the images folder. The problem was caused by improper configuration of the php.ini file. Of course one problem leads to another. So now the images don't show, for some reason the image just shows all black. I am working on it.

Reply With Quote
  #3 (permalink)  
Old November 17th, 2006, 10:18 AM
Authorized User
 
Join Date: Mar 2005
Location: arima, West Indies, Trinidad and Tobago.
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to arimakidd
Default

Ok, the thumbnails are showing fine. I have encountered another problem that I have decided to highlight in another topic. With regards to this topic the original code given in the book does need some editing. From curly braces have to be taken off and some lines really do have to be deleted.

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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
Chapter 2 - End of chapter exercises whizzkid1892 BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 1 July 30th, 2008 12:02 PM
Generics chapter 12 difficult chapter i found ...? Larryz C# 2005 1 July 4th, 2007 09:40 PM
The infamous Access denied problem... RMASSEY MySQL 1 December 27th, 2004 11:20 PM



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


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