Screenshot:
index.php:
form:
index.php:
<body> <form name="zips" method="post"> <div > <table width="600" border="0" align="center" cellpadding="10" cellspacing="0"
style="border-collapse:collapse; border:#ccc 1px solid;" id="tbl"> <tr> <td align="center"><input type="checkbox" name="files[]" value="for.php" />
<span> for.php</span></td> </tr> <tr><td align="center" colspan="2"><input type="submit" name="submit"
value="create as zip" /></td></tr> </table> </div> </form> </body>
form:
<?php if(isset($_POST['submit'])){ $post = $_POST; $file_folder = "files/"; if(extension_loaded('zip')){ if(isset($post['files']) and count($post['files']) > 0){ $zip = new ZipArchive(); $zip_name = time().".zip"; if($zip->open($zip_name, ZIPARCHIVE::CREATE)!==TRUE){ $error .= "* Sorry ZIP creation failed at this time<br/>"; } foreach($post['files'] as $file){ $zip->addFile($file_folder.$file); } $zip->close(); if(file_exists($zip_name)){ header('Content-type: application/zip'); header('Content-Disposition: attachment; filename="'.$zip_name.'"'); readfile($zip_name); unlink($zip_name); } }} } ?>
No comments:
Post a Comment