How Create a Zip File Using PHP

Posted by Unknown On Sunday 17 November 2013 0 comments


     Hello friends now we are going to discus a small code for creating Zip file using PHP. Creating zip file is simple as comparing with author languages.

PHP have a very useful class called ZipArchive ,To create multiple zip files in this post i will show you how create a ZIP file 





https://app.box.com/s/2zg0c554wceby2bsa2gk



Source

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

<?phpfunction zipFilesDownload($file_names$archive_file_name$file_path)
{
    
$zip = new ZipArchive();
  
    if (
$zip->open($archive_file_nameZIPARCHIVE::CREATE) !== TRUE) {
        exit(
"cannot open <$archive_file_name>\n");
    }
  
    foreach (
$file_names as $files) {
        
$zip->addFile($file_path $files$files);
    }
    
$zip->close();
  
    
header("Content-type: application/zip");
    
header("Content-Disposition: attachment; filename=$archive_file_name");
    
header("Pragma: no-cache");
    
header("Expires: 0");
    
readfile("$archive_file_name");
    exit;
}
$fileNames     = array('files/file1.docx',
    
'files/file1.pdf');$zip_file_name 'myFile.zip';

$file_path     dirname(__FILE__) . '/';
zipFilesDownload($fileNames$zip_file_name$file_path);
?>

 


0 comments:

Post a Comment

Fashion