Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Hi guys
Got a problem and getting a bit desparate on my chances of solving it.
I am trying to display images that are stored in db
[syntax="sql"]
CREATE TABLE upload (
id INT NOT NULL AUTO_INCREMENT,
name VARCHAR(30) NOT NULL,
type VARCHAR(30) NOT NULL,
size INT NOT NULL,
content MEDIUMBLOB NOT NULL,
PRIMARY KEY(id)
);As I work on it I managed to get one image to show, but I need to show all of them, currently there's 3 jpeg ons
Here's my code so far:[/syntax]
Code: Select all
<?php
$host = "";
$user = "";
$password = "";
$database = "";
$connection = mysql_connect($host,$user,$password)
or die ("Couldn't connect to a server");
$database = mysql_select_db($database, $connection);
$query = "SELECT id, type, content FROM upload";
$result = mysql_query($query) or die('Error, query failed');
$count = mysql_num_rows($result);
if(mysql_num_rows($result) == 0)
{
echo "Database is empty <br>";
}
else
{
while($results = mysql_fetch_array($result))
{
$content = $results["content"];
$type = $results["type"];
$id = $results["id"];
$image= imagecreatefromstring($content);
switch ($type){
case "image/jpeg":
header("Content-type: image/jpeg");
$display = imagejpeg ($image);
imagedestroy($image);
break;
case "image/png":
header("Content-type: image/png");
$display = imagepng($image);
imagedestroy($image);
break;
case "image/gif":
header ("Content-type: image/gif");
$display = imagegif($image);
imagedestroy($image);
break;
}
}
}
?>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?
for ($i=0; i<$count; $i++){
echo $count;
echo' <img src="' . $display . '" /><br />';
}
?>
</body>
</html>feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]