hi
this code below will save an image in the database for you and
will show it again when you use show file and will enter the file id n the data base
for sure you must make some changes
and make a db like:
dbname=strong
table name= file
fields= fileid (int)
fileex (varcar20)
filename(longblob)
at your mysql
<html>
<head>
<title>image to mysql</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?
function connectdb()
{
global $link;
$link=mysql_connect("localhost","root","root");
mysql_select_db("strong");
}
?>
<?
connectdb();
$dbname="strong";
if (!isset($submit)) {
?>
<form method="POST" action="" enctype=multipart/form-data>
<table>
<tr><td></td><td></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">
<input type="submit" name="ss" value="show file"></td></tr>
</table>
</form>
<? }if(isset($submit)){
$hndl=fopen($imgfile,"r");
$imgdata='';
while(!feof($hndl))
{
$imgdata.=fread($hndl,2048);
}
$imgdata=addslashes($imgdata);
$imgtype='';
$sql = "INSERT INTO file VALUES(NULL,'". $imgtype ."','". $imgdata ."')";
$result=mysql_db_query($dbname,$sql,$link);
if($result){echo 'true';}
fclose($hndl);
}?>
<?
if(isset($ss))
{ ?>
<form name="form1" method="post" action="">
<input type="text" name="myid">
<input type="submit" name="id" value="Submit">
</form>
<? }?>
<?
if(isset($id))
{
$query="select * from file where fileid=$myid ";
$result=mysql_db_query($dbname,$query,$link);
$rs=mysql_fetch_array($result);
$name=$rs[2];
$fname="mahak6.gif";
$file_handle = fopen($fname, "wb");
if($file_handle){echo 'file opended';}
$file_bytes = $name;
$i=fwrite($file_handle, $file_bytes, strlen($file_bytes));
if($i) {echo 'write on file completed';}
header('Content-type: gif/jpg');
$s="location :" . $fname;
echo $s;
header("$s");
}
?>
<p> </p>
</body>
</html>