Hi,
I have made an upload page so I can upload images to a mysql database with some text describing the picture. Does anyone know a way or can anyone point me to a tutorial that will let me take every image from the database table and populate an image gallery on a website?
Also when I add an image to my table, it add on to the end, I need them to addd on to the start or to add them to the website starting from the last image: the last image added should be the first image in the website gallery!
Here my files
index.php
<form action="hme.php" method="POST" enctype="multipart/form-data">
File:<br />
<input type="file" name="image"> <br /><br />
Description:<br />
<input type=text name="details"><br /><br/>
<input type="submit" value="Upload">
</form>
<?php
error_reporting(E_ALL ^ E_NOTICE);
//connect to database
include 'connect.php';
//file properties
$file = $_FILES['image'] ['tmp_name'];
if (!isset($file))
echo "Please select an image.";
else
{
$image = addslashes(file_get_contents($_FILES['image'] ['tmp_name']));
$image_name = addslashes($_FILES['image'] ['name']);
$image_size = getimagesize($_FILES['image'] ['tmp_name']);
$adetails = $_POST['details'];
if ($image_size==FALSE)
echo "That's not an image! Choose an image file.";
else
{
if (!$insert = mysql_query("INSERT INTO store VALUES (NULL,'$image_name','$image', '$adetails')"))
echo "Image not uploaded!";
else
{
$lastid = mysql_insert_id();
echo "Image uploaded.<p />Your image:<p /><img src=get.php?id=$lastid>";
}
}
}
?>
</body>
</head>
</html>
connect.php
<?php
mysql_connect("localhost","root","xxxxxx") or die(mysql_error());
mysql_select_db("databaseimage") or die(mysql_error());
?>
get.php
<?php
include 'connect.php';
$id = addslashes($_REQUEST['id']);
$image = mysql_query("SELECT * FROM store WHERE id=$id");
$image = mysql_fetch_assoc($image);
$image = $image['image'];
header("Content-type: image/jpeg");
echo $image;
?>
show.php(I usedd this just to see what my table looked like)
<?php
//show information
ini_set('display_errors',1);
error_reporting(E_ALL);
$conn = mysql_connect("localhost","root","phoebemay12");
if(!$conn)
{
echo mysql_error();
}
$db = mysql_select_db("databaseimage",$conn);
if(!$db)
{
echo mysql_error();
}
$q = "SELECT * FROM store";
$r = mysql_query("$q",$conn);
if($r)
{
while($row=mysql_fetch_array($r))
{
//header("Content-type: text/html");
echo "<br />";
echo $row['details'];
echo "<br />";
echo "<img src=get.php?id=".$row['id']." />";
}
}
else
{
echo mysql_error();
}
?>
Thanks for looking