php - Zip files from checkbox and download -


i trying make list of files directory have them shown in form via checkboxes. when user checks files want download have them zipped , downloaded. have no experience in php have managed make list checkboxes , download script attached button when selected should start download doesn't clear boxes.if possible store copy of zip folder on server in case user re-download in amount of time. here code have. let me know went wrong , please explain corrections code trying learn little project.

 <?php     $error = "";        //error holder     if(isset($_post['createzip'])){         $post = $_post;              $file_folder = "files/";    // folder load files         if(extension_loaded('zip')){    // checking zip extension available             if(isset($post['files']) , count($post['files']) > 0){    // checking files selected                 $zip = new ziparchive();            // load zip library                  $zip_name = time().".zip";          // zip name                 if($zip->open($zip_name, ziparchive::create)!==true){       // opening zip file load files                     $error .=  "* sorry zip creation failed @ time<br/>";                 }                 foreach($post['files'] $file){                                    $zip->addfile($file_folder.$file);          // adding files zip                 }                 $zip->close();                 if(file_exists($zip_name)){                     // push download zip                     header('content-type: application/zip');                     header('content-disposition: attachment; filename="'.$zip_name.'"');                     readfile($zip_name);                     // remove zip file exists in temp path                     unlink($zip_name);                 }              }else                 $error .= "* please select file zip <br/>";         }else             $error .= "* dont have zip extension<br/>";     } ?> 

here's checkbox

<?php  if ($handle = opendir('./')) { while (false !== ($entry = readdir($handle))) {     if ($entry != "." && $entry != "..") {         echo '<input type="checkbox" name="files[]" value=".$entry"/> '.$entry. '<br />';     } } closedir($handle); ?> 


Comments

Popular posts from this blog

service - Android MediaPlayer calls onCompletion before it already finished -

javascript - Training Neural Network to play flappy bird with genetic algorithm - Why can't it learn? -

javascript - Create a stacked percentage column -