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 March 12th, 2011, 05:24 PM
Registered User
 
Join Date: Mar 2011
Location: NE Pennsylvania
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Unhappy Chapter 7 Image not displaying

I'm trying to get the "check_image.php" code to work. Everything seems to be there but the image does not display, only a place holder.
Here is the code I'm using:
Code:
<?php

//connect to the database
$link = mysql_connect("localhost", "john", "**********")
  or die("Could not connect: " . mysql_error());
mysql_select_db("MovieSite", $link) 
  or die (mysql_error());
?>
<pre>
<?php
  echo "<br>_POST<br>"  ;
  print_r($_POST);
  echo "<br>_FILES<br>";
  print_r($_FILES);
  echo "<br>";
?>
</pre>
<?php

//make variables available
$image_caption = $_POST['image_caption'];
$image_username = $_POST['image_username'];
$image_tempname = $_FILES['image_filename']['name'];
$today = date("Y-m-j");

echo "<br>image_tempname: " . $image_tempname;
echo "<br>";

//upload image and check for image type
$ImageDir ="/var/www/images/";
$ImageName = $ImageDir . $image_tempname;

echo "<br>ImageName: " . $ImageName;
echo "<br>";

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

			echo "<br>File Moved";
  //get info about the image being uploaded
  list($width, $height, $type, $attr) = getimagesize($ImageName);

  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.";
  }

 //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 . $ext;
    
    echo "<br>newfilename: ". $newfilename;
    echo "<br>ImageName: ". $ImageName;
    echo "<br>";

   rename($ImageName, $newfilename);
 
}

?>
<html>
<head>
<title>Here is your pic!</title>
</head>
<br><br>
<p>Here is the picture you just uploaded to our servers:</p>
<img src="images/<?php echo $lastpicid . $ext; ?>" align="left">
<strong><?php echo $image_caption; ?></strong><br>
This image  is a <?php echo $ext; ?> image.<br>
It is <?php echo $width; ?> pixels wide
and <?php echo $height; ?> pixels high.<br>
It was uploaded on <?php echo $today; ?>.
</body>
</html>
Again everything seems to be on the web page but the picture. I'd attach a screen shot but since I'm new I guess I can't.

Any ideas what I'm doing wrong or is there some setting that needs tweaking?

Thanks,
John
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
Displaying an image ran_stb ASP.NET 3.5 Professionals 4 April 10th, 2010 03:17 AM
Error At Displaying An Image asters .NET Framework 1.x 0 September 23rd, 2008 04:20 AM
Displaying Image in a gridview cholletivinod ASP.NET 2.0 Basics 0 July 3rd, 2007 12:29 AM
Image not displaying shoakat ASP.NET 2.0 Professional 2 June 22nd, 2007 10:02 AM
displaying an image from file stream into an image sanjeet ADO.NET 0 September 23rd, 2005 10:28 AM



All times are GMT -4. The time now is 10:06 AM.


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