Wrox Programmer Forums
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old March 12th, 2011, 06:24 PM
Registered User
Join Date: Mar 2011
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:

//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());
  echo "<br>_POST<br>"  ;
  echo "<br>_FILES<br>";
  echo "<br>";

//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";
    case 2:
      $ext = ".jpg";
    case 3:
      $ext = ".png";
      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)
            ('$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);

<title>Here is your pic!</title>
<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; ?>.
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?


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

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.