Hello Everyone,
I currently have a database called "Gallery", that contains one table called "Images" with a field called "Filename".
How come when I use the code in
Fig 1 the image uploads, but when i use the code in
Fig 2, the image doesn't display?
I am currently using Xampp on Windows XP.
Fig 1
Code:
<?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("Gallery", $con);
if (($_FILES["file"]["type"] == "image/bmp")
|| ($_FILES["file"]["type"] == "image/jpg")
&& ($_FILES["file"]["size"] < 90000))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
if (file_exists("upload/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
$file = ("upload/" . $_FILES["file"]["name"]);
move_uploaded_file($_FILES["file"]["tmp_name"],
"upload/" . $_FILES["file"]["name"]);
echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
mysql_query("INSERT INTO Images (path)
VALUES('$file')");
}
}
}
else
{
echo "Invalid file";
}
?>
Fig 2
Code:
<?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("Gallery", $con);
$result = mysql_query("select * from Images");
while($row = mysql_fetch_array($result))
{
// print an HTML image tag
echo "<img src='upload/".$row['filename']."' alt='".htmlentities($row['caption'])."' title='".htmlentities($row['caption'])."'>";
// print the caption and 2 line breaks
echo "<br />".$row['caption']."<br /><br />";
}
mysql_close($con);
?>
Many Thanks,