Postingan lainnya
Buku Ini Koding!
Baru!
Buku ini akan jadi teman perjalanan kamu belajar sampai dapat kerjaan di dunia programming!
Kelas Premium!
Belajar Javascript untuk website
Gunakan kupon "mulaijs" untuk diskon 75 ribu!
upload download web
bagaimana cara upload download? PHP Version 5.6.32
7 Jawaban:
@hikmabqory iya gan mungkin punya program upload download file
Pertama buat database terlebih dahulu [img] https://4.bp.blogspot.com/-HlkW3eKh2mU/Va5LJPBfufI/AAAAAAAAAC4/XMdhLb6Zuj0/s400/db.jpg [/img]
Kedua buat Folder untuk menampung file-file yang di upload, misalnya folder files
Ketiga buat script untuk form uploadnya
script form upload.php
<pre> <html> <title>Form Upload</title> <body>
<form enctype="multipart/form-data" method="POST" action="hasil_upload.php"> File yang di upload : <input type="file" name="fupload"><br> Deskripsi File : <br> <textarea name="deskripsi" rows="8" cols="40"></textarea><br> <input type=submit value=Upload> </form>
</pre>
Keempat buat Script hasil upload
script hasil_upload.php
<pre> <?php // Baca lokasi file sementar dan nama file dari form (fupload) $lokasi_file = $_FILES['fupload']['tmp_name']; $nama_file = $_FILES['fupload']['name'];
// Tentukan folder untuk menyimpan file $folder = "files/$nama_file";
// tanggal sekarang $tgl_upload = date("Ymd");
// Apabila file berhasil di upload if (move_uploaded_file($lokasi_file,"$folder")){ echo "Nama File : <b>$nama_file</b> sukses di upload";
// Masukkan informasi file ke database $konek = mysqli_connect("localhost","root","","upload");
$query = "INSERT INTO upload (nama_file, deskripsi, tgl_upload) VALUES('$nama_file', '$_POST[deskripsi]', '$tgl_upload')";
mysqli_query($konek, $query); } else{ echo "File gagal di upload"; } ?> </pre>
Hasil Output [img] https://3.bp.blogspot.com/-ymBmTs2EzU0/Va5NQvMWbDI/AAAAAAAAADU/wfUVBmH6ioM/s400/uplod.jpg [/img] <img src=' https://2.bp.blogspot.com/-OU5s4obbCeg/Va5NQSmV-2I/AAAAAAAAADI/rxnFzryha9Y/s400/succes.jpg '>
script download.php
<pre> <html> <title>Aplikasi Download</title> <body> <?php $konek = mysqli_connect("localhost","root","","upload");
$query = "SELECT * FROM upload ORDER BY id_upload DESC"; $hasil = mysqli_query($konek, $query);
while ($r = mysqli_fetch_array($hasil)){ echo "Nama File : <b>$r[nama_file]</b> <br>"; echo "Deskripsi : $r[deskripsi] <br>"; echo "<a href="donlot.php?file=$r[nama_file]">Download File</a><hr><br>"; } ?>
Kedua saya buat file berisi script untuk menyimpan file yang di download
script simpan.php
<?php // Tentukan folder file yang boleh di download $folder = "files/";
// Lalu cek menggunakan fungsi file_exist if (!file_exists($folder.$_GET['file'])) { echo "<h1>Access forbidden!</h1> <p> Anda tidak diperbolehkan mendownload file ini.</p>"; exit; }
// Apabila mendownload file di folder files else { header("Content-Type: octet/stream"); header("Content-Disposition: attachment; filename="".$_GET['file']."""); $fp = fopen($folder.$_GET['file'], "r"); $data = fread($fp, filesize($folder.$_GET['file'])); fclose($fp); print $data; } ?> </pre>
Hasil utput <img src=' https://2.bp.blogspot.com/-zHMUdAqBOcQ/Va5RNTFNOvI/AAAAAAAAADk/tY3dEPkf76o/s400/download.jpg '>
@samsularifin05 field 5 apa gan tulisannya ga jelas di tabel
<img src=' https://4.bp.blogspot.com/-HlkW3eKh2mU/Va5LJPBfufI/AAAAAAAAAC4/XMdhLb6Zuj0/s1600/db.jpg '>
keterangan hits apa gan @samsularifin05