azmicolejr

aplot

Oct 14th, 2015
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. $allowed_ext = array('doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'pdf', 'rar', 'zip');
  2. $file_name = $_FILES['file']['name']; // File adalah nama_kgt dari tombol input pada form
  3. $file_ext = strtolower(end(explode('.', $file_name)));
  4. $file_size = $_FILES['file']['size'];
  5. $file_tmp = $_FILES['file']['tmp_name'];
  6. $lokasi = 'file/kegiatan/'.$nama_kgt.'-'.$file_name;
  7.  
  8. if(in_array($file_ext, $allowed_ext) === true)
  9. {
  10. if($file_size <= 3145728) // Max Upload 3 MB | 1 MB = 1048576 KB
  11. {
  12. move_uploaded_file($file_tmp, $lokasi);
  13. $sql = "INSERT INTO kegiatan (id_kgt,nama_kgt,ket,tg_mulai,tg_akhir,type,size,file)
  14. VALUES('$id_kgt','$nama_kgt','$ket','$tg_mulai','$tg_akhir','$file_ext','$file_size','$lokasi')";
  15.  
  16. if(mysqli_query($conn, $sql))
  17. {echo "<script>alert('Upload Kegiatan berhasil! Klik ok untuk melanjutkan');location.replace('kegiatan_list.php')</script>";}
  18. else {echo "Error updating record: " . mysqli_error($conn);}
  19. }
  20. else{echo "<script>alert('ERROR: Besar ukuran file (file size) maksimal 3 Mb!');history.go(-1)</script>";}
  21. }
  22. else {echo "<script>alert('Jenis file tidak sesuai!');history.go(-1)</script>";}
Advertisement
Add Comment
Please, Sign In to add comment