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