|
 |
|
 |
 |
03-29-2007, 01:04 AM
|
#1 (permalink)
|
|
Salchester
Join Date: Jul 2005
Location: In a house
Posts: 230
|
Why Won't This Work?
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,
__________________
Many Thanks, in advance!
Salchester.
The Future Is Here - Are You Ready?
|
|
|
03-29-2007, 06:31 AM
|
#2 (permalink)
|
|
Newbie
Join Date: Jun 2002
Location: Denmark
Posts: 1,680
|
Take a closer look at your code:
Quote:
...
PHP Code:
$file = ("upload/" . $_FILES["file"]["name"]); ... mysql_query("INSERT INTO Images (path) VALUES('$file')");
...
PHP Code:
echo "<img src='upload/".$row['filename']."' alt='".htmlentities($row['caption'])."' title='".htmlentities($row['caption'])."'>";
...
|
Now look again and see if that dosn't ring a bell.
|
|
|
03-29-2007, 09:48 AM
|
#3 (permalink)
|
|
Salchester
Join Date: Jul 2005
Location: In a house
Posts: 230
|
Why Won't This Work?
Redhead,
What am I supposed to be looking at, I don't understand?
I don't recognize any of this?
Many Thanks, much appreciated!!!
__________________
Many Thanks, in advance!
Salchester.
The Future Is Here - Are You Ready?
|
|
|
03-29-2007, 12:18 PM
|
#4 (permalink)
|
|
Code Monkey
Join Date: Aug 2002
Location: Boston, MA
Posts: 79
|
Where in Fig 1 do you upload it to a field called filename?
Are you getting the captions to display?
-Toe
__________________
|
|
|
03-29-2007, 11:08 PM
|
#5 (permalink)
|
|
Salchester
Join Date: Jul 2005
Location: In a house
Posts: 230
|
Why Won't This Work?
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) ' Oops, "path" should be changed to "filename"
VALUES('$file')");
}
}
}
else
{
echo "Invalid file";
}
?>
If you mean are the Image Captions displaying, the answer currenlty no as fore now I just trying to get the images to display, through reading the image path from the database.
Many Thanks,
__________________
Many Thanks, in advance!
Salchester.
The Future Is Here - Are You Ready?
|
|
|
03-31-2007, 05:11 AM
|
#6 (permalink)
|
|
Newbie
Join Date: Jun 2002
Location: Denmark
Posts: 1,680
|
Quote:
|
What am I supposed to be looking at, I don't understand?
|
Let me make it clear then, in your storing into the database, you store the filename with a leading upload/ since you store it into your $file.
In your displaying you retrieve this filename with the leading upload/ but when displaying you add another upload/ to it, so teh <img> tag has a source of upload/upload/file.ext this will neveer display your file....
Is that clear enough, or wasn't that exactly what my two snippits of code was showing you ????
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -8. The time now is 02:12 AM.
|
Copyright © 2000-2006, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
Open Circle
|
 |
|