Jasa pembuatan Aplikasi dan website

header ads

Scrif Simpan File Gambar dan File lain Dengan Php

buat dahulu database nya.

CREATE TABLE IF NOT EXISTS `produk` (
  `id_produk` int(5) NOT NULL AUTO_INCREMENT,
  `id_kategori` int(5) NOT NULL,
  `nama_produk` varchar(100) COLLATE latin1_general_ci NOT NULL,
  `deskripsi` text COLLATE latin1_general_ci NOT NULL,
  `telpon` int(12) NOT NULL,
  `email` varchar(20) COLLATE latin1_general_ci NOT NULL,
  `tgl_masuk` date NOT NULL,
  `photo` varchar(100) COLLATE latin1_general_ci NOT NULL,
  `ukuran` int(11) NOT NULL,
  `type` varchar(50) COLLATE latin1_general_ci NOT NULL,
  `level` varchar(1) COLLATE latin1_general_ci NOT NULL,
  `tgl` date NOT NULL,
  PRIMARY KEY (`id_produk`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=227 ;




Buat file simpan.php dan masukan scrif in:
<?php
include "koneksi.php";
if(isset($_POST['submit'])){
      $id_kategori=addslashes(htmlentities(ucwords($_POST['id_kategori'])));
$nama_produk=addslashes(htmlentities(ucwords($_POST['nama_produk'])));
$deskripsi=addslashes(htmlentities($_POST['deskripsi']));
$telpon=addslashes(htmlentities($_POST['telpon']));
$email=addslashes(htmlentities($_POST['email']));
$level=addslashes(htmlentities($_POST['level']));
$nama_photo=$_FILES['photo']['name'];
$type = $_FILES['photo']['type'];
$ukuran=$_FILES['photo']['size'];
if(empty($id_kategori) || empty($nama_produk) || empty($telpon) || empty($email) || empty($nama_photo)){
echo "Maaf, Form belum lengkap!! <a href=iklan.php> Silahkan ulangi</a>";
}else{
$query_email=mysql_query("select * from produk where id_produk='$id_produk'");
$cek=mysql_num_rows($query_email);
if($cek>0){
echo "Maaf, kode sudah di pakai!! <a href=iklan.php> Silahkan ulangi</a>";
}else{
if($type != "image/gif"  &&  $type != "image/jpg"  && $type != "image/jpeg" && $type != "image/png") {
echo "File Yang Di izinkan Hanya jpg,jpeg,png,gif!! <a href=iklan.php> Silahkan ulangi</a>";
}else{
if($ukuran>1000000){
echo "File Yang Di izinkan Hanya berukuran kurang dari 1MB!! <a href=input.php> Silahkan ulangi</a>";
}else{
$uploaddir='./photo/'; //folder simpan photo
$rnd=date(His);
$nama_file_upload=$rnd.'-'.$nama_photo;
$alamatfile=$uploaddir.$nama_file_upload;

if (move_uploaded_file($_FILES['photo']['tmp_name'],$alamatfile))
{
$query=mysql_query("insert into produk(id_kategori,nama_produk,deskripsi,telpon,email, photo,ukuran,type,level,tgl)
values('$id_kategori','$nama_produk','$deskripsi','$telpon','$email','$nama_file_upload','$ukuran','$type','$level',NOW())");

header('location:iklan.php');

}}}}}}
?>

//buat file from input
nb: form harus sesuai
<form  name="postform" method="post" action="aksi_produk.php" enctype="multipart/form-data">
<div>
<span><label>JUDUL IKLAN</label></span>
<span><input name="nama_produk" type="text" class="textbox"></span>
</div><div>
<span><label>KATEGORI</label></span>
<span><select name="id_kategori" class="textbox">
<?php
$sql=mysql_query("SELECT * FROM kategori GROUP BY id_kategori ASC");
while ($data=mysql_fetch_array($sql)) {
echo '<option value="',$data ['id_kategori'],'">',$data['id_kategori'],'</option>';
}
?>
 </select></span>
 </div> <div>
<span><label>HP / TELPON</label></span>
<span><input name="telpon" type="text" class="textbox"></span>
 </div> <div>
<span><label>EMAIL</label></span>
<span><input name="email" type="text" class="textbox"></span>
</div><div>
<span><label>GAMBAR</label></span>
<span><input name="photo" type="file" class="textbox"></span>
 </div><div>
<span><input name="level" type="hidden" class="textbox" value="N"></span>
 </div><div>    
<span><label>DESKRIFSI</label></span>
<span><textarea  name="deskripsi"> </textarea></span>
</div> <div>
<span><input type="submit" value="Submit" name="submit" class="myButton"></span>
</div>
</form>

Post a Comment

0 Comments