php - Zipfile created with ZipArchive unzips to cpgz -


i have page you're going able download multiply files zip. in code works fine, when i'm trying unzip it, unzips filename.zip.cpgz.

it might have fact use wordpress, because tried before without , worked fine...

when open file in text editor following error messages:

warning: filesize(): stat failed unstraight.zip in /users/johannaskogh/desktop/workspace/olivia_schough/wp-content/themes/schoughs/page-research.php on line 16

warning: cannot modify header information - headers sent (output started @ /users/johannaskogh/desktop/workspace/olivia_schough/wp-content/themes/schoughs/page-research.php:16) in /users/johannaskogh/desktop/workspace/olivia_schough/wp-content/themes/schoughs/page-research.php on line 16

warning: readfile(unstraight.zip): failed open stream: no such file or directory in /users/johannaskogh/desktop/workspace/olivia_schough/wp-content/themes/schoughs/page-research.php on line 18

warning: unlink(unstraight.zip): no such file or directory in /users/johannaskogh/desktop/workspace/olivia_schough/wp-content/themes/schoughs/page-research.php on line 19

here's code handling zip, on top of file:

<?php  $error = ""; //error holder if(isset($_post['createzip'])) {     $files = $_post['files'];     $zipname = time() . ".zip"; // zip name     $zip = new \ziparchive(); // load zip library     $zip->open($zipname, ziparchive::create);     foreach ($files $file) {         $zip->addfile($file);     }     $zip->close();     // push download zip     header('content-type: application/zip');     header('content-disposition: attachment; filename=' . $zipname);     header('content-length: ' . filesize($zipname));     ob_clean();     readfile($zipname);     unlink($zipname); } ?> 

and here rest of it:

<?php get_header(); ?>  <div class="content"> <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <article class="article article--about theme">     <div class="article__part--bottom">         <div class="container">             <h1 class="article__title"><?php the_title();?></h1>             <div class="article__content">             <?php the_content(); ?>         </div>     </div>                 <div class="container">         <div class="article__content">             <form name="zips" method="post">                  <?php                 $upload_dir = wp_upload_dir();                  // path directory                 $directory = $upload_dir['path'] . '/research/';                 $iterator = new \directoryiterator($directory);                 ?>                  <div class="checkbox-list">                 <?php foreach ($iterator $file) {                     if ($file->isfile()) {                         ?>                         <div class="checkboxes">                             <input type="checkbox" name="files[]" value="<?php echo $file->getfilename(); ?>">                             <h3 class="font-maxima">"<?php echo $file->getfilename(); ?>"</h3>                             <span class="smaller-font">the unstraight museum</span>                         </div>                      <?php                      }                 }     <input type="submit" name="createzip" value="download zip"> </form>  <?php get_footer(); ?> 

i tried change

$file->getfilename(),

to

$file->getrealpath();

in

<input type="checkbox" name="files[]" value="<?php echo $file->getfilename(); ?>">

then zip unziped should be, problem here whole path file, don't want. want file/files.

okay manage solve problem, didn't have path folder.

i changed value in form $file->getrealpath(); ?>">

and make sure whole path file didn't along in zip-file, added $zip->addfile($file, basename($file));


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -