<table cellspacing="0" cellpadding="0"><tr><td class="t_f" id="postmessage_65133"> <div class="blockcode"> <div id="code_x4H"><ol> <li> </li> <li> <?php <li> $error = ""; //error holder</li> <li> if(isset($_POST['createpdf'])){</li> <li> $post = $_POST; </li> <li> $file_folder = "files/"; // folder to load files</li> <li> if(extension_loaded('zip')){ // Checking ZIP extension is available</li> <li> if(isset($post['files']) and count($post['files']) > 0){ // Checking files are selected</li> <li> $zip = new ZipArchive(); // Load zip library </li> <li> $zip_name = time().".zip"; // Zip name</li> <li> if($zip->open($zip_name, ZIPARCHIVE::CREATE)!==TRUE){ // Opening zip file to load files</li> <li> $error .= "* Sorry ZIP creation failed at this time<br>";</li> <li> }</li> <li> foreach($post['files'] as $file){ </li> <li> $zip->addFile($file_folder.$file); // Adding files into zip</li> <li> }</li> <li> $zip->close();</li> <li> if(file_exists($zip_name)){</li> <li> // push to download the zip</li> <li> header('Content-type: application/zip');</li> <li> header('Content-Disposition: attachment; filename="'.$zip_name.'"');</li> <li> readfile($zip_name);</li> <li> // remove zip file is exists in temp path</li> <li> unlink($zip_name);</li> <li> }</li> <li> <li> }else</li> <li> $error .= "* Please select file to zip <br>";</li> <li> }else</li> <li> $error .= "* You dont have ZIP extension<br>";</li> <li> }</li> <li>?></li> <li> <li> <li> <li><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></li> <li><title>Download As Zip</title></li> <li> <li> <li><center><h1>Create Zip</h1></center></li> <li><form name="zips" method="post"> <li><?php if(!empty($error)) { ?></li> <li><p style=" border:#C10000 1px solid; background-color:#FFA8A8; color:#B00000;padding:8px; width:588px; margin:0 auto 10px;"><?php echo $error; ?></p></li> <li><?php } ?></li> <li><table width="600" border="1" align="center" cellpadding="10" cellspacing="0" style="border-collapse:collapse; border:#ccc 1px solid;"> <li> <tr> <li> <td width="33" align="center">*</td> </li> <li> <td width="117" align="center">File Type</td> </li> <li> <td width="382">File Name</td> </li> <li> </li> </tr> </li> <li> <tr> <li> <td align="center"><input type="checkbox" name="files[]" value="flowers.jpg"></td> </li> <li> <td align="center"><img src="files/image.png" title="Image" style="max-width:90%" style="max-width:90%" alt="php的zip压缩代码 " ></td> </li> <li> <td>flowers.jpg</td> </li> <li> </li> </tr> </li> <li> <tr> <li> <td align="center"><input type="checkbox" name="files[]" value="fun.jpg"></td> </li> <li> <td align="center"><img src="files/image.png" title="Image" style="max-width:90%" style="max-width:90%" alt="php的zip压缩代码 " ></td> </li> <li> <td>fun.jpg</td> </li> <li> </li> </tr> </li> <li> <tr> <li> <td align="center"><input type="checkbox" name="files[]" value="uvamsi.docx"></td> </li> <li> <td align="center"><img src="files/doc.png" title="Document" style="max-width:90%" style="max-width:90%" alt="php的zip压缩代码 " ></td> </li> <li> <td>uvamsi.docx</td> </li> <li> </li> </tr> </li> <li> <tr> <li> <td align="center"><input type="checkbox" name="files[]" value="abc.pdf"></td> </li> <li> <td align="center"><img src="files/pdf.png" title="pdf" style="max-width:90%" style="max-width:90%" alt="php的zip压缩代码 " ></td> </li> <li> <td>abc.pdf</td> </li> <li> </li> </tr> </li> <li> <tr> <li> <td colspan="3" align="center"> <li> <input type="submit" name="createpdf" style="border:0px; background-color:#800040; color:#FFF; padding:10px; cursor:pointer; font-weight:bold; border-radius:5px;" value="Download as ZIP"> </li> <li> <input type="reset" name="reset" style="border:0px; background-color:#D3D3D3; color:#000; font-weight:bold; padding:10px; cursor:pointer; border-radius:5px;" value="Reset"> </li> <li> </li> </td> </li> <li> </li> </tr> </li> <li> </table></li> <li> <li> </form></li> <li> <li> <li> </li> <li> </ol></div> <em onclick="copycode($('code_x4H'));">复制代码</em> </div> <br> </td></tr></table> <div class="ptg mbm mtn"> php, zip</div> <div id="comment_65133" class="cm"> </div> <div id="post_rate_div_65133"></div> <br><br>