Guest
Public paste!

Aaron

By: a guest | May 8th, 2008 | Syntax: PHP | Size: 1.00 KB | Hits: 91 | Expires: Never
This paste has a previous version, view the difference. Copy text to clipboard
  1. <?
  2. class Archive {
  3.         function __construct($archive, $create = false) {
  4.                 $this->archive = new ZipArchive;
  5.                
  6.                 if($create && file_exists($archive)) {
  7.                         unlink($archive);
  8.                 }
  9.                
  10.         if(file_exists($archive) && !$create) {
  11.                 $this->archive->open($archive);
  12.         } else {
  13.                 $this->archive->open($archive, ZipArchive::CREATE);
  14.                 }
  15.         }
  16.        
  17.         public function read($filename) {
  18.                 if($this->archive->locateName($filename) !== false) {
  19.                         return $this->archive->getFromName($filename);
  20.                 }
  21.                 return false;
  22.         }
  23.        
  24.         public function delete($filename) {
  25.                 if ($this->archive->locateName($filename) !== false) {
  26.                         $this->archive->deleteName($filename);
  27.                 }
  28.         }
  29.        
  30.         public function write($filename, $content) {
  31.                 $this->delete($filename);
  32.                 return $this->archive->addFromString($filename, $content);
  33.         }
  34.        
  35.         public function addFile($filename, $localname) {
  36.                 $this->delete($filename);
  37.                 return $this->archive->addFile($localname, $filename) or die ("Could not add file: $localname");
  38.         }
  39. }