p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Beginning PHP 6, Apache, MySQL 6 Web Development ISBN: 9780470391143 (http://p2p.wrox.com/forumdisplay.php?f=476)
-   -   Chapter 7 - Exercise (http://p2p.wrox.com/showthread.php?t=78581)

rickymartini76@yahoo.it March 16th, 2010 05:36 PM

Chapter 7 - Exercise
 
Hello all, i have some problem with caption on chapter 7, code is exact and i believe that the problem is th GD file on php that don't load arial caracter...
How i can resolve this problem?

Moreover, Can I have some help about 7.1 exercise?
Code is next, file vacation.htm:

Code:

<html>
 <head>
  <title>Go on a Virtual Vacation!</title>
 </head>
 <body>
  <form method="post" action="upload_image.php" enctype="multipart/form-data">
  <table>
    <tr>
    <td><label for="image_caption">Image Name or Caption</label><br/>
      <em>Example: Wish you were here!</em></td>
    <td><input id="image_caption" name="image_caption" type="text" size="55"/></td>
    </tr><tr>
      <td><label for="image_username">Your Name:</label></td>
      <td><input id="image_username" name="image_username" type="text" size="15"></td>
    </tr><tr>
      <td><label for="image_filename">Upload Image:</label></td>
      <td><input id="image_filename" name="image_filename" type="file" /></td>
    </tr>
    </table>
    <p><em>Acceptable image formats include: JPG/JPEG</em></p>
    <p>Select your destination:</p>
    <table>
    </tr><tr>
      <td><input type="radio" id="destination_1" name="destination" value ="beach" /></td>
      <td><label for="destination_1"><img src="images/beach.jpg"></label></td>
    </tr><tr>
      <td><input type="radio" id="destination_2" name="destination" value ="golfcourse" /></td>
      <td><label for="destination_2"><img src="images/golfcourse.jpg">
    </label></td>
    </tr><tr>
      <td><input type="radio" id="destination_3" name="destination" value ="mountains" /></td>
      <td><label for="destination_3"><img src="images/mountains.jpg"></label>
      </td>
    </tr>
    </table>
    <p style="text-align: center">
    <input type="submit" name="Submit" value="Submit" />
    <input type="reset" value="Clear Form" /></p>
    </form>
  </body>
  </html>

And upload_image.php file is :

Code:

<?php
// Filtra le variabili in arrivo
$image_caption = (isset($_POST['image_caption'])) ? $_POST['image_caption'] : '';
$image_username = (isset($_POST['image_username'])) ? $_POST['image_username'] : 'Anonymous';
$destination = $_POST['destination'];
$image_tempname = $_FILES['image_filename']['name'];
$today = date('Y-m-d');

// Modificare questo percorso in base alla directory che contiene le immagini
$dir ='C:/Programmi/Apache Software Foundation/Apache2.2/htdocs/images';

$image_name = $dir . $image_tempname;

if (move_uploaded_file($_FILES['image_filename']['tmp_name'], $image_name))
{
  // Recupera le informazioni sull'immagine che sta per essere inviata
  list($width, $height, $type, $attr) = getimagesize($image_name);
 
  if ($type != IMAGETYPE_JPEG) {
      echo '<p><strong>Sorry, but the file you uploaded was not a JPG ' .
            'file.<br/>Please hit your back button and try again.</strong></p>';
  } else {
      // L'immagine è accettabile, si può procedere
      $dest_image_name = $dir . $destination . '.jpg';

      $image = imagecreatefromjpeg($image_name);
      list($width2, $height2, $type2, $attr2) = getimagesize($dest_image_name);

      $image2 = imagecreatefromjpeg($dest_image_name);
      imagecopymerge ($image2, $image, 0,0,0, 0, $width, $height, 100);
  }

  header('Content-type:image/jpeg');
  imagejpeg($image2);
}
?>

When first file call upload_image.php there is next Error message:
Warning: getimagesize(C:/Programmi/Apache Software Foundation/Apache2.2/htdocs/imagesbeach.jpg) [function.getimagesize]: failed to open stream: No such file or directory in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\upload_image.php on line 27

Warning: imagecreatefromjpeg(C:/Programmi/Apache Software Foundation/Apache2.2/htdocs/imagesbeach.jpg) [function.imagecreatefromjpeg]: failed to open stream: No such file or directory in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\upload_image.php on line 29

Warning: imagecopymerge(): supplied argument is not a valid Image resource in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\upload_image.php on line 30

Warning: Cannot modify header information - headers already sent by (output started at C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\upload_image.php:27) in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\upload_image.php on line 33

Warning: imagejpeg(): supplied argument is not a valid Image resource in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\upload_image.php on line 34

Thank you for your helps….

PeterPeiGuo March 16th, 2010 07:15 PM

Tried your code, I had to mofify couple of things to make sure the images actually exist. Check the following:
1) Is C:/Programmi/Apache Software Foundation/Apache2.2/htdocs where you installed your httpd?
2) Is imagesbeach.jpg the exact name of your image? (There are three images, and you have to check and make sure that they all named as the program expected.)

PeterPeiGuo March 16th, 2010 07:32 PM

This line is suspicious (unless that's intended and you did name your files like imagebeach.jpg):
Code:

$dir ='C:/Programmi/Apache Software Foundation/Apache2.2/htdocs/images'
You probably meant (I added a / at the end of the string):
Code:

$dir ='C:/Programmi/Apache Software Foundation/Apache2.2/htdocs/images/'
Or modify the following line:
Code:

      $dest_image_name = $dir . $destination . '.jpg';
And change it to:
Code:

      $dest_image_name = $dir . '/' . $destination . '.jpg';
One way or another you have to add that /, otherwise 'image' won't appear as a folder name but part of your image's name (like imagebeach.jpg)


All times are GMT -4. The time now is 04:21 AM.

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