|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|||
|
PHP Image Database
After many hours, I have finally come up with the following code, that saves a file onto the server, in a folder called "Upload"....
...Does anybody know how to store the image path into a database called Photos and table called "Images" containing a column call "Path"? The following is the code currently being used. PHP Code:
Many Thanks, Moderator's Note: PHP tags added by Nilpo Last edited by Nilpo : February 7th, 2007 at 12:06 PM. |
|
|||
|
PHP Image Database
SandMan,
How do I put the following code inside a loop, so that it displays all the images/paths, within the database? <img src="uploads/<?php echo $imagename ?>"> What is "$imagename", where would it be in the following code? Code:
<?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("photos", $con);
if (($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
&& ($_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";
}
?>
|
|
||||
|
you'll need to loop through your record set like this: http://resources.bravenet.com/artic..._mysql_basics/3
|
|
|||
|
PHP Image Database
SandMan,
What is stored in the $imagename variable?, i currently have a database called photos, and a table called images containing one field/column called path. How do i pass the information in the path field/column to the image on the page, to display the appropriate image. The following is what i have so far in terms of coding, to the first image. The data stored inside the database, is in the following format. Example: upload/45_j11.jpg Code:
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("photos", $con);
$imagename= mysql_query("SELECT * FROM images
WHERE path");
while($row = mysql_fetch_array($result))
{
}
?>
</head>
<body>
<img src="$imagename">
</body>
</html>
Last edited by Salchester : February 12th, 2007 at 07:26 AM. |
![]() |
| Viewing: Dev Hardware Forums > SOFTWARE > Programming > PHP Image Database |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|