Advertisement
Guest User

Untitled

a guest
Feb 18th, 2020
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. if(isset ($_POST['upload'])){
  2. $allowed_ext = array('doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'pdf', 'rar', 'zip');
  3. $file_name = $_FILES['file']['name'];
  4.  
  5. //$name_parts = explode('.', $file_name);
  6. $file_ext= strtolower(end($name_parts));
  7.  
  8. $file_ext = strtolower(end(explode('.', $file_name)));
  9. $file_size = $_FILES['file']['size'];
  10. $file_tmp = $_FILES['file']['tmp_name'];
  11.  
  12. $nama =$_FILES ['file']['name'];
  13. $tgl = date("Y-m-d");
  14.  
  15. if(in_array($file_ext, $allowed_ext) === true){
  16. if($file_size < 1044070){
  17. $lokasi = 'files/'.$nama.'.'.$file_ext;
  18. move_uploaded_file($file_tmp, $lokasi);
  19. $cone = mysqli_connect('localhost','root','','gis');
  20. $in = mysqli_query($cone, "INSERT INTO tb_tempat VALUES(NULL, '$tgl', '$nama', '$file_ext', '$file_size', '$lokasi')");
  21. if($in){
  22. echo '<div class="ok">SUCCESS: File berhasil di Upload!</div>';
  23. }else{
  24. echo '<div class="error">ERROR: Gagal upload file!</div>';
  25. }
  26. }else{
  27. echo '<div class="error">ERROR: Besar ukuran file (file size) maksimal 1 Mb!</div>';
  28. }
  29. }else{
  30. echo '<div class="error">ERROR: Ekstensi file tidak di izinkan!</div>';
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement