can some one show me the best way to show images from a database in a table
ive got a database called myFiles and a table below
create table myBlobs
(
blobId int auto_increment not null,
blobTitle varchar(50),
blobData longblob,
blobType varchar(50),
primary key(blobId),
unique id(blobId)
);
showfiles.php below
<?php
$sConn = mysqli_connect("localhost","root", "admin","myFiles")or die("Couldn't connect to database server");
$dbQuery = "SELECT blobId, blobTitle, blobType,blobData ";
$dbQuery .= "FROM myBlobs ";
$dbQuery .= "ORDER BY blobTitle ASC";
$result = $sConn->query($dbQuery) or die("Couldn't get file list");
//$fileType = $row["blobType"];
//header("Content-type: $row['blobType']");
?>
<table border="1" cellpadding="0" cellspacing="0" bordercolor="#111111" width="100%">
<tr>
<td width="25%" bgcolor="#FF9900" height="21">
<p style="margin-left: 10"><b><font size="2" face="Verdana" color="#FFFFFF">Description</font></b></td>
<td width="25%" bgcolor="#FF9900" height="21">
<p style="margin-left: 10"><b><font face="Verdana" size="2" color="#FFFFFF">Type</font></b></td>
<td width="25%" bgcolor="#FF9900" height="21">
<p style="margin-left: 10"><b><font face="Verdana" size="2" color="#FFFFFF">File</font></b></td>
<td width="25%" bgcolor="#FF9900" height="21">
<p style="margin-left: 10"><b><font face="Verdana" size="2" color="#FFFFFF">photo</font></b></td>
</tr>
<tr>
<?php while($row = mysqli_fetch_array($result)){?>
<td width="25%" bgcolor="#FFDCA8" height="21">
<p style="margin-left: 10; margin-right: 10">
<font face="Verdana" size="1">
<?php echo $row["blobTitle"]; ?>
</font>
</td>
<td width="25%" bgcolor="#FFDCA8" height="21">
<p style="margin-left: 10">
<font face="Verdana" size="1">
<?php echo $row["blobTitle"]; ?>
</font>
</td>
<td width="25%" bgcolor="#FFDCA8" height="21">
<p style="margin-left: 10"><font face="Verdana" size="1">
<a href="downloadfile.php?blobId=<?php echo $row["blobId"]; ?>">
Download now
</a></font>
</td>
<td width="25%" bgcolor="#FFDCA8" height="21">
<p style="margin-left: 10">
<font face="Verdana" size="1">
<?php
header("Content-type: $row[blobType]");
echo $row["blobData"]; ?>
</font>
</td>
</tr>
<?php
}
echo "</table>";
?>
this outputs the raw data for the image file in collum 4, but when i click the link in collum 3 the image gets shown in another page downloadfile.php below what i an tring to do is show the image in collum 4 not the raw data and get rid of the download link altogether.
<?php
global $blobId;
if(!is_numeric($blobId))die("Invalid blobId specified");
// Database connection variables
$sConn = mysqli_connect("localhost","root", "admin","myFiles")or die("Couldn't connect to database server");
$dbQuery = "SELECT blobType, blobData ";
$dbQuery .= "FROM myBlobs ";
$dbQuery .= "WHERE blobId = $blobId";
$result =$sConn->query($dbQuery) or die("Couldn't get file list");
if(mysqli_num_rows($result) == 1)
{
$row =$result->fetch_row();
//$fileType = $row[0];
//echo $fileType;
//$fileContent = $row[1];
header("Content-type: $row[0]");
echo $row[1];
}else{echo "Record doesn't exist.";}
?>
ive been on this for days but and going nowhere all the tutorials on the web just seem to show the link method can any body help a newbee (stressed)
thanks in advance
john
ps tutorial link