| | |||||||
| |||||||
| |||||||
|
|
|
|
|
|
|
upload image to mysql database By : cana <?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> Click to Download File
More Miscellaneous Code Articles |
| |
| |