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