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 PHP 6, Apache, MySQL 6 Web Development ISBN: 9780470391143
This is the forum to discuss the Wrox book Beginning PHP 6, Apache, MySQL 6 Web Development by Timothy Boronczyk, Elizabeth Naramore, Jason Gerner, Yann Le Scouarnec, Jeremy Stolz; ISBN: 9780470391143
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning PHP 6, Apache, MySQL 6 Web Development ISBN: 9780470391143 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 March 16th, 2010, 05:36 PM
Authorized User
 
Join Date: Dec 2009
Posts: 14
Thanks: 3
Thanked 0 Times in 0 Posts
Unhappy 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….
Reply With Quote
  #2 (permalink)  
Old March 16th, 2010, 07:15 PM
Friend of Wrox
 
Join Date: Dec 2008
Location: , , .
Posts: 238
Thanks: 2
Thanked 20 Times in 19 Posts
Default

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.)
Reply With Quote
  #3 (permalink)  
Old March 16th, 2010, 07:32 PM
Friend of Wrox
 
Join Date: Dec 2008
Location: , , .
Posts: 238
Thanks: 2
Thanked 20 Times in 19 Posts
Default

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)
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 8 exercise 3 Will BOOK: Beginning C# 3.0 : An Introduction to Object Oriented Programming ISBN: 978-0-470-26129-3 8 March 4th, 2010 04:15 AM
Chapter 3 - Exercise 3 AndyN BOOK: Beginning Cryptography with Java 3 August 16th, 2006 03:09 PM
Chapter 5 - Exercise 1 scgtman BOOK: Beginning Visual Basic 2005 Databases ISBN: 978-0-7645-8894-5 3 May 16th, 2006 08:10 PM
Chapter 4, Exercise 3 DRAYKKO BOOK: Beginning Java 2 3 July 9th, 2004 02:34 PM
Chapter 8, Exercise 4 cjo BOOK: Beginning ASP.NET 1.0 0 November 3rd, 2003 02:26 PM



All times are GMT -4. The time now is 03:07 AM.


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