Search
 
SCRIPT & CODE EXAMPLE
 

PHP

Download multiple files as zip in PHP

<?php

/* create a compressed zip file */
function createZipArchive($files = array(), $destination = '', $overwrite = false) {

   if(file_exists($destination) && !$overwrite) { return false; }

   $validFiles = array();
   if(is_array($files)) {
      foreach($files as $file) {
         if(file_exists($file)) {
            $validFiles[] = $file;
         }
      }
   }

   if(count($validFiles)) {
      $zip = new ZipArchive();
      if($zip->open($destination,$overwrite ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) == true) {
         foreach($validFiles as $file) {
            $zip->addFile($file,$file);
         }
         $zip->close();
         return file_exists($destination);
      }else{
          return false;
      }
   }else{
      return false;
   }
}

$fileName = 'myzipfile.zip';
$files = array('uploads/profile1.jpeg', 'uploads/profile2.jpeg');
$result = createZipArchive($files, $fileName);

header("Content-Disposition: attachment; filename="".$fileName.""");
header("Content-Length: ".filesize($fileName));
readfile($fileName);

?>
Comment

how to make zip in php by multiple files

$files = array('readme.txt', 'test.html', 'image.gif');
$zipname = 'file.zip';
$zip = new ZipArchive;
$zip->open($zipname, ZipArchive::CREATE);
foreach ($files as $file) {
  $zip->addFile($file);
}
$zip->close();

header('Content-Type: application/zip');
header('Content-disposition: attachment; filename='.$zipname);
header('Content-Length: ' . filesize($zipname));
readfile($zipname);
Comment

lDownload multiple files as a zip-file using php

$files = array('readme.txt', 'test.html', 'image.gif');
$zipname = 'file.zip';
$zip = new ZipArchive;
$zip->open($zipname, ZipArchive::CREATE);
foreach ($files as $file) {
  $zip->addFile($file);
}
$zip->close();
Comment

PREVIOUS NEXT
Code Example
Php :: jwt auth laravel auth without password field 
Php :: php serialize() 
Php :: time left laravel seconds 
Php :: int to char php 
Php :: or where in codeigniter 
Php :: make project in laravel 7 
Php :: get ip address of client php 
Php :: laravel parent child same table 
Php :: pg_dump with user name password 
Php :: laravel json response 
Php :: php DateTime comparation 
Php :: php rotate image 
Php :: php count 
Php :: mac brew install php redis 
Php :: php set environment variable 
Php :: wordpress add meta user 
Php :: get user by meta wp 
Php :: get post in php 
Php :: php artisan route cache 
Php :: laravel collection distinct 
Php :: php sha512 hash 
Php :: add shortcode in wordpress 
Php :: ubuntu 7.2 deleted php 
Php :: how to fetch data from url in php properly 
Php :: php date diff in days 
Php :: laravel relation select fields 
Php :: php array_intersect 
Php :: laravel resource set status code 
Php :: how to make arrays in php 
Php :: TRANSACTON LARAVEL QUERY BUILDER 
ADD CONTENT
Topic
Content
Source link
Name
6+4 =