| Assalamulaikum..Selamat Pagi agan-agan... ane udah coba nih coding untuk download beberapa file lalu di .zip, tapi kog gk konsisten gan antara file yg di pilih untuk di download dengan hasilnya yg udah di .zip ??? ane pake cek box untuk download per barisnya... smoga ada pencerahan.. Terima Kasih, smoga Berkah... |
| ini koding untuk tampilan file2 yg akan di download, Point cekbox nya ada pada tag <td> yg kedua gan, :
while ($data=mysql_fetch_array($hasil)) { ?> <tr> <td><a href="delete-file-mhs-web.php?id=<?php echo $data['id'];?>" onclick="return confirm('Anda yakin menghapus file dengan NIM <?php echo $data['nim_mhs'];?> ?');"> <i class='icon-trash'></i>Hapus</a> <a href="download-single.php?id=<?php echo $data['id'];?>"> <i class='icon-download'></i>Download</a> </td> <td><input type="checkbox" name="data[]" value="<?php echo $data['id'];?>"/></td> </tr> <?php } |
| ini file untuk proses submit pilihan2 tadi (Sumber dari webinfopedia.com) :
<?php //This script is developed by www.webinfopedia.com //For more examples in php visit www.webinfopedia.com function zipFilesAndDownload($file_names,$archive_file_name,$file_path) { $zip = new ZipArchive(); //create the file and throw the error if unsuccessful if ($zip->open($archive_file_name, ZIPARCHIVE::CREATE )!==TRUE) { exit("cannot open <$archive_file_name>\n"); } //add each files of $file_name array to archive foreach($file_names as $files) { $zip->addFile($file_path.$files,$files); //echo $file_path.$files,$files."<br />"; } $zip->close(); //then send the headers to foce download the zip file $zipped_size = filesize($archive_file_name); header("Content-Description: File Transfer"); header("Content-type: application/zip"); header("Content-Type: application/force-download");// some browsers need this header("Content-Disposition: attachment; filename=$archive_file_name"); header("Expires: 0"); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); //header('Pragma: public'); header("Pragma: no-cache"); header("Content-Length: ".$zipped_size); ob_clean(); flush(); readfile("$archive_file_name"); unlink("$archive_file_name"); // Now delete the temp file (some servers need this option) exit; }
if (isset($_POST['bt_download'])) { include "../../koneksi.php"; //$data=$_POST['data']; $data=filter_var_array($_POST['data']);//works but it's the wrong method for ($i=0;$i < sizeof($data); $i++){ $sql="select * from file where id in('$data[$i]')"; //Mysql query to fetch file names $query=mysql_query($sql); //create an empty array $file_names = array(); //fetch the names from database while($row = mysql_fetch_array($query, MYSQL_NUM)){ //Add the values to the array //Below 3 ,eams the the number of the mysql table column $file_names[] = $row[3]; } $namafile=date("d-m-y");
//Archive name $archive_file_name="File-Praktikum-Web-Klp.".$row['kelompok']."-".$namafile.".zip"; //Download Files path $file_path='../file_mhs/'; } //call the function zipFilesAndDownload($file_names,$archive_file_name,$file_path); } ?> |
Tidak ada komentar:
Posting Komentar