öncelikle veritabanında aşağıdaki sql'i çalıştır.
CREATE TABLE `tbl_image` (
`id` int(11) NOT NULL auto_increment,
`image` blob NOT NULL,
`type` varchar(30) collate latin1_general_ci NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=28 ;
daha sonra aşağıdaki kodu image.php olarak kaydererek denemeni yapabilirsin.
<?php
$cn = mysql_connect("localhost","root","");
mysql_select_db("db_image",$cn);
if ($act=='view'){
$sql="SELECT * FROM tbl_image where id=$id";
$rst=mysql_query($sql) or die('gagal');
$data=mysql_fetch_array($rst);
$type=$data[type];
Header("Content-type: $type");
echo $data[image];
}
if ($act=='del'){
$sql="DELETE FROM tbl_image where id=$id";
$rst=mysql_query($sql) or die('gagal');
}
if($submit)
{
$type = $_FILES['file']['type'];
copy ($_FILES['file']['tmp_name'], "tmp/tmp.jpg") or die ("Could not copy");
$filer="tmp/tmp.jpg";
$handle = fopen($filer, "r");
$pure = addslashes(fread($handle, filesize($filer)));
$sql = "insert into tbl_image(image,type) values('$pure','$type')";
$result = mysql_query($sql,$cn)or die(mysql_error());
}
$sql="SELECT * FROM tbl_image";
$rst=mysql_query($sql) or die('gagal');
while ($data=mysql_fetch_array($rst)){
$id=$data[id];
echo "picture no $id <a href='./image.php?act=del&id=$id'>delete</a><br><img src='./image.php?act=view&id=$id'><br><br>";
}
?>
<html>
<head>
<title>upload image</title>
</head>
<body>
<form action='image.php' method='post' enctype="multipart/form-data">
<input type='file' name='file'>
<input type='submit' name='submit'>
</form>
</body>
</html>upload image to database sql adresine bakarsan çalışan bir örneği var, sorun yaşarsan pm ile messenger iste yardımcı olurum.