<?php $error = ""; //error holder if(isset($_POST['btnDownload'])){ $post = $_POST; $file_folder = "application_download/"; // folder to load files if(extension_loaded('zip')){ // Checking ZIP extension is available if(isset($post['files']) and count($post['files']) > 0){ // Checking files are selected $zip = new ZipArchive(); // Load zip library $zip_name = time().".zip"; // Zip name if($zip->open($zip_name, ZIPARCHIVE::CREATE)!==TRUE){ // Opening zip file to load files $error .= "* Sorry ZIP creation failed at this time<br/>"; } foreach($post['files'] as $file){ $zip->addFile($file_folder.$file); // Adding files into zip } $zip->close(); if(file_exists($zip_name)){ // push to download the zip header('Content-type: application/zip'); header('Content-Disposition: attachment; filename="'.$zip_name.'"'); readfile($zip_name); // remove zip file is exists in temp path unlink($zip_name); } }else $error .= "* Please select file to zip <br/>"; }else $error .= "* You dont have ZIP extension<br/>"; } ?> <html> <head> <title>ThaiCreate.Com PHP & MySQL Tutorial</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head> <body> <script language="JavaScript"> function ClickCheckAll(vol) { var i=1; for(i=1;i<=document.frmMain.hdnCount.value;i++) { if(vol.checked == true) { eval("document.frmMain.files"+i+".checked=true"); } else { eval("document.frmMain.files"+i+".checked=false"); } } } </script> <form name="frmMain" action="" method="post"> <?php if(!empty($error)) { ?> <p style=" border:#C10000 1px solid; background-color:#FFA8A8; color:#B00000;padding:8px; width:588px; margin:0 auto 10px;"><?php echo $error; ?></p> <?php } ?> <? $objConnect = mysql_connect("localhost","root","password") or die("Error Connect to Database"); $objDB = mysql_select_db("checkall2"); $strSQL = "SELECT * FROM tbl_application ORDER BY id ASC limit 0,5"; mysql_query("SET NAMES UTF8"); $objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]"); ?> <table width="600" border="1"> <tr> <th width="10"> <div align="center"> <input name="CheckAll" type="checkbox" id="CheckAll" value="Y" onClick="ClickCheckAll(this);"> </div></th> <th width="10"> <div align="center">id </div></th> <th width="120"> <div align="center">regis_id </div></th> <th width="300"> <div align="center">project_name </div></th> <th width="100"> <div align="center">duedate </div></th> <th width="50"> <div align="center">file </div></th> </tr> <? $i = 0; while($objResult = mysql_fetch_array($objQuery)) { $i++; ?> <tr> <td align="center"><input type="checkbox" name="files[]" id="files<?=$i;?>" value="application_download/<?php echo $objResult['file'] ;?>"></td> <td><div align="center"><?=$objResult["id"];?></div></td> <td><?=$objResult["regis_id"];?></td> <td><?=$objResult["project_name"];?></td> <td align="center"><?=$objResult["duedate"];?></td> <td align="center"><a href="application_download/<?php echo $objResult['file'] ;?>"><img src="pdf-icon.png" width="24" height="24" border="0" alt=""></a></td> </tr> <? } ?> </table> <? mysql_close($objConnect); ?> <input type="submit" name="btnDownload" value="Download as ZIP"> <input type="hidden" name="hdnCount" value="<?=$i;?>"> </form> </body> </html>
<html> <head> <title>ThaiCreate.Com PHP Zip</title> </head> <body> <?php $ZipName = "MyFiles/MyZip.zip"; require_once("dZip.inc.php"); // include Class $zip = new dZip($ZipName); // New Class $zip->addFile("thaicreate1.txt", "thaicreate1.txt"); // Source,Destination $zip->addFile("thaicreate2.txt", "thaicreate2.txt"); $zip->addDir("MySub"); // Add Folder $zip->addFile("thaicreate3.txt", "MySub/thaicreate3.txt"); // Add file to Sub $zip->addFile("thaicreate4.txt", "MySub/thaicreate4.txt"); $zip->save(); echo "Zip Successful Click <a href=$ZipName>here</a> to Download"; ?> </body> </html>
เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง