CODE
<?php
$submit=$_POST['submit'];
$cn = mysql_connect("localhost","root","");
mysql_select_db("db_image",$cn);
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>";
echo "<img src='tmp/image.php?act=view&id=$id'><br><br>";
//echo $data[0];
//echo $data[1];
//echo $data[2];
}
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');
} else{
echo "yyuiuffgtytu";
}
?>
<html>
<head>
<title>upload image</title>
</head>
<body>
<form action="<? echo $PHP_SELF;?>" method="post" enctype="multipart/form-data">
<input type="file" name="file">
<input type="submit" name="submit">
</form>
</body>
</html>