Hey, I am kind of new to PHP/MySQL, so I am hoping someone will be able to help me out. I have the code below to upload a photo to a database and then retrieve it and display it to the screen. I am using a Digi Web server to host the site and for database storage.
However, my problem is that the picture wont display after being uploaded to the database. But, when I use a different server (UCD Server), I can get the same code to work, displaying the picture.
Can anyone sugest a reason that the Digi web server would be different and if so a fix?
Cheers
Dave
File test_imagedb_view.php
<html>
<head>
<style type="text/css">
//this does the roll-over stuff
#cssexample a {
position:relative;
}
#cssexample a img{
display:block;
position:absolute;
top:-999px;
left:0;
}
#cssexample a:hover img {
top:-50px;
left:0;
}
</style>
</head>
<body>
<form method="post" enctype="multipart/form-data">
<table width="350" border="0" cellpadding="1" cellspacing="1" class="box">
<tr>
<td width="246">
<input type="hidden" name="MAX_FILE_SIZE" value="2000000">
<input name="userfile" type="file" id="userfile">
</td>
<td width="80"><input name="upload" type="submit" class="box" id="upload" value=" Upload "></td>
</tr>
</table>
</form>
<form method="post">
<input name="id" type="text" id="id">
<input name="delete" type="submit" id="add" value="delete imgid">
</form>
<?
$dbuser="xxxx";
$dbpass="xxxx";
$dbname = "xxxx";
$dbserver = "xxxx";
$dbconn =
@mysql_connect($dbserver,$dbuser,$dbpass) or exit("SERVER Unavailable");
@mysql_select_db($dbname,$dbconn) or exit("DB Unavailable");
//Retrieve the images - uses the other php file test_imagedb_create to do so
$sql = "SELECT imgid,imgtype FROM tblimage ORDER BY imgid";
$result =
@mysql_query($sql,$dbconn) or exit("QUERY FAILED!");
echo "<table border=1>\n";
echo "<tr><th>imgid</th><th>imgtype</th><th>imgdata</th></tr>\n";
while ($rs=mysql_fetch_array($result)) {
echo "<tr><td>".$rs[0]."</td>";
echo "<td>".$rs[1]."</td>";
echo "<td><p id=cssexample><a>View full size<img height=400 width=400 src=\"test_imagedb_create.php?imgid=".$rs[0]."\"></a><br><img height=80 width=80 src=\"test_imagedb_create.php?imgid=".$rs[0]."\"></p></td></tr>\n";
};
echo "</table>\n";
mysql_close($dbconn);
?>
</body>
</html>
File test_imagedb_create.php
<?
$dbuser="xxxx";
$dbpass="xxxx";
$dbname = "xxxx";
$dbserver = "xxxx";
$dbconn =
@mysql_connect($dbserver,$dbuser,$dbpass) or exit("SERVER Unavailable");
@mysql_select_db($dbname,$dbconn) or exit("DB Unavailable");
$sql = "SELECT imgtype,imgdata FROM tblimage WHERE imgid=".$_GET["imgid"];
$result =
@mysql_query($sql,$dbconn) or exit("QUERY FAILED!");
$contenttype =
@mysql_result($result,0,"imgtype");
$image =
@mysql_result($result,0,"imgdata");
header("Content-type: $contenttype");
echo $image;
mysql_close($dbconn);
?>
Database code
CREATE TABLE `tblimage` (
`imgid` int(3) unsigned NOT NULL auto_increment,
`imgtype` varchar(16) NOT NULL default '',
`imgdata` mediumblob,
PRIMARY KEY (`imgid`)
) TYPE=MyISAM;