Ok I downloaded code snippet from here: http://phpbuilder.com/snippet/download.php?type=snippet&id=1642
Here is what my code looks like:
DB.php
<?
function connectdb(){
mysql_connect("private","private","private") or die(mysql_error());
mysql_select_db("private") or die(mysql_error());
}
?>
index.php
<?php
if (!isset($submit)) {
?>
<form method="POST" action="" enctype=multipart/form-data>
<table>
<tr><td>Type</td><td><select name="imgtype"><option value="image/gif">GIF</option><option value="image/jpeg">JPEG</option></select></td></tr>
<tr><td>File</td><td><input type="file" name="imgfile"></td></tr>
<tr><td></td><td><input type="submit" name="submit" value="upload"><input type="reset" value="reset"></td></tr>
</table>
</form>
<?php
} else {
include "includes/DB.php";
connectdb();
$hndl=fopen($imgfile,"rb");
$imgdata='';
while(!feof($hndl)){
$imgdata.=fread($hndl,2048);
}
$imgdata=addslashes($imgdata);
$sql = "INSERT INTO tblimage VALUES(NULL,'". $imgtype ."','". $imgdata ."')";
@mysql_query($sql) or die(mysql_error());
fclose($hndl);
?>
<a href="view.php">view image</a>
<?php
};
?>
view.php
<?php
include "includes/DB.php";
connectdb();
$sql = "SELECT imgid,imgtype FROM tblimage ORDER BY imgid";
$result = @mysql_query($sql) or die(mysql_error());
echo "<table border=1>";
echo "<tr><th>imgid</th><th>imgtype</th><th>imgdata</th></tr>";
while ($rs = mysql_fetch_array($result)) {
echo "<tr><td>".$rs[0]."</td>";
echo "<td>".$rs[1]."</td>";
echo '<td><img src=\"post.php?imgid="$rs[0]"\" width=100 height=100></td></tr>';
}
echo "</table>";
?>
post.php
<?
include "includes/DB.php";
connectdb();
$sql = "SELECT imgtype,imgdata FROM tblimage WHERE imgid=". $imgid;
$result = @mysql_query($sql) or exit("QUERY FAILED!");
$row = mysql_fetch_object($result);
$contenttype = @mysql_result($result,0,"imgtype");
$image = @mysql_result($result,0,"imgdata");
header("Content-type: $row->imgtype");
echo $row->imgdata;
?>
Using that I am building my own custom image gallery to be used on the homepage as Screenshot of the Day.
The problem I am having is actually getting the code to display my image: http://unleashed.farimynn.com/gallery/view.php
I know it uploaded the image to the database but I just can't seem to figure it out why it won't display the image.
Any help much appreciated
Steve