This example describes the PHP generation zip file class. Share to everyone for your reference. as follows:
<?php/* By:matt Ford Purpose:basic class to create Zipfiles/class ZipFile {public $files = array ();
Public $settings = NULL;
Public $fileInfo = Array ("name" => "", "Numfiles" => 0, "Fullfilepath" => ");
Private $fileHash = "";
Private $zip = "";
Public function __construct ($settings) {$this->zipfile ($settings);
The Public Function ZipFile ($settings) {$this->zip = new Ziparchive ();
$this->settings = new StdClass ();
foreach ($settings as $k => $v) {$this->settings-> $k = $v;
The public function Create () {$this->filehash = MD5 (Implode (",", $this->files)); $this->fileinfo["Name" = $this->filehash.
". zip";
$this->fileinfo["numfiles"] = count ($this->files);
$this->fileinfo["Fullfilepath"] = $this->settings->path. "/" .
$this->fileinfo["name"]; if (file_exists ($this->fileinfo["Fullfilepath"]) {return Array (false, already created:). $this,; fileinfo["Fullfilepath"]);
else {$this->zip->open ($this->fileinfo["Fullfilepath"], ziparchive::create);
$this->addfiles ();
$this->zip->close (); Return Array (True, new file created:.
$this->fileinfo["Fullfilepath"]);
The Private Function AddFiles () {foreach ($this->files as $k) {$this->zip->addfile ($k, basename ($k));
}} $settings = Array ("Path" => dirname (__file__));
$zipFile = new ZipFile ($settings);
$zipFile->files = Array ("./images/navoff.jpg", "./images/navon.jpg");
List ($success, $error) = $zipFile->create (); if ($success = = True) {//success} else {//error because: $error}?>
I hope this article will help you with your PHP programming.