Source Code



How Create a Zip File Using PHP

  • midhun pottmmal
  • 18 November 2013 at 13:45
  • PHP
  • 278
  • 108
  • United States
 


Author: midhun pottmmal Language: United States
License: Freeware
Size: 0 KB
Downloads: 31 times

 

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

Source


<?php
function zipFilesDownload($file_names,$archive_file_name,$file_path)
{
    $zip = new ZipArchive();

    if ($zip->open($archive_file_name, ZIPARCHIVE::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);
?>


comments powered by Disqus

Related Code

Icon Extractor - full delphi source code

Func-In Delphi Example

Create Search and Get in The Middle String

PHP Script for PING

Draggable

PHP Sample From CSUSB

Bootstrap UI Kits

Diagram Studio

Simple Graph Component

Delphi Example Code



Category