Thursday, May 22, 2008

nyimpan gambar menggunakan php mysql

buat databasedi mysql

create database gambar;

aktifkan
use gambar;

lalu buat tabel

CREATE TABLE `image` ( `ImageId` int(10) NOT NULL AUTO_INCREMENT, `Image` longblob, `FileType` varchar(32) DEFAULT NULL, keterangan text, PRIMARY KEY (`ImageId`) );

====
simpan.php
untuk melakukan upload gambar dan keterangan
==

if ($_POST['Submit']) {
if ($_POST['MAX_FILE_SIZE'] >= $_FILES['file']['size']) {
//print_r($_FILES);
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("gambar");
$photo = addslashes(fread(fopen($_FILES['file']['tmp_name'], "r"),
$_FILES['file']['size']));
$ktr=$_POST['ket'];
$query = sprintf("INSERT INTO image(Image, FileType, keterangan) VALUES
('%s', '%s', '%s')", $photo, $_FILES['file']['type'], $ktr);
if (mysql_query($query)) {
$messages[] = "Your files is successfully store in database";
} else {
$messages[]= mysql_error();
}
} else {
$messages[]="The file is bigger than the allowed size please resize";
}
}
?>


Add Image




if (isset($messages)) {
foreach ($messages as $message) {
print $message ."
";
}
}
?>
Program Gambar


 

















Keterangan Gambar
   
Pilih Gambar

 








==
setelah itu jalankan menggunakan browser
sudah bisa nyimpan gambar didatabase deh heeee
sippp tenan

No comments: