コード例 #1
0
 /**
  * Undo the last actions on the open zip file.
  * @param string $mixed
  * @return boolean @params mixed $mixed : undo changes to an archive by index(int), name(string), all ('all' | '*' | blank) usage : $this->Zip->undo(1); $this->Zip->undo('myText.txt'); $this->Zip->undo('*'); $this->Zip->undo('myText.txt, myText1.txt'); $this->Zip->undo(array(1, 'myText.txt'));
  */
 function undo($mixed = '*')
 {
     if (is_array($mixed)) {
         foreach ($mixed as $value) {
             $constant = is_string($value) ? 'Name' : 'Index';
             if (!$this->zip->{'unchange' . $constant}($value)) {
                 return false;
             }
         }
     } else {
         $mixed = explode(',', $mixed);
         if (in_array($mixed[0], ['*', 'all'])) {
             if (!$this->zip->unchangeAll()) {
                 return false;
             }
         } else {
             foreach ($mixed as $name) {
                 if (!$this->zip->unchangeName($name)) {
                     return false;
                 }
             }
         }
     }
     return true;
 }
コード例 #2
0
ファイル: Import.php プロジェクト: casati-dolibarr/corebos
         $input = fopen($url, 'r');
         if (!file_put_contents($uploadfilename, $input)) {
             $smarty->assign("MODULEIMPORT_FAILED", "true");
             $uploadfilename = null;
         }
     }
 }
 if ($uploadfilename) {
     // Check ZIP file contents for extra directory at the top
     $za = new ZipArchive();
     $za->open($uploadfilename);
     for ($i = 0; $i < $za->numFiles; $i++) {
         $entryName = $za->getNameIndex($i);
         $firstSlash = strpos($entryName, '/');
         if ($entryName === 'manifest.xml' || $entryName === './manifest.xml' || $firstSlash === false) {
             $za->unchangeAll();
             break;
         }
         $newEntryName = substr($entryName, $firstSlash + 1);
         if ($newEntryName !== false) {
             $za->renameIndex($i, $newEntryName);
         } else {
             $za->deleteIndex($i);
         }
     }
     $za->close();
     $package = new Vtiger_Package();
     $moduleimport_name = $package->getModuleNameFromZip($uploadfilename);
     if ($moduleimport_name == null) {
         $smarty->assign("MODULEIMPORT_FAILED", "true");
         $smarty->assign("MODULEIMPORT_FILE_INVALID", "true");
コード例 #3
0
 /**
  * @info is public for PHP 5.3 compatibility, should be private
  */
 public function addEmptyDir(\ZipArchive $zip, $dir)
 {
     if (!$zip->addEmptyDir($dir)) {
         $zip->unchangeAll();
         $zip->close();
         throw new RuntimeException(sprintf('unable to add %s to the zip file', $dir));
     }
 }
コード例 #4
0
ファイル: functions.php プロジェクト: DylanGroenewoud/PVNG
 /**
  * Create a zip archive using the ZipArchive class
  *
  * You should not use this function directly. Use the 'zip' function above.
  *
  * @param  array  $sources     List of paths to files and directories to be archived.
  * @param  string $destination Destination file where the archive will be stored.
  * @param  array  $exclude     Directories and/or files to exclude from archive, defaults to empty array.
  * @return mixed               Returns TRUE on success or an instance of WP_Error on failure.
  */
 function _zip_create_ziparchive($sources, $destination, $exclude = array())
 {
     $zip = new ZipArchive();
     if ($res = $zip->open($destination, ZIPARCHIVE::CREATE) != true) {
         return new WP_Error('ziparchive', $res);
     }
     foreach ($sources as $source) {
         if (!@is_readable($source)) {
             continue;
         }
         if (@is_dir($source)) {
             $files = directory_list($source, true, $exclude);
             if (is_wp_error($files)) {
                 $zip->unchangeAll();
                 if (file_exists($destination)) {
                     delete_path($destination);
                 }
                 return $files;
             }
             foreach ($files as $file) {
                 if (!@is_readable($file)) {
                     continue;
                 }
                 if (@is_dir($file)) {
                     $zip->addEmptyDir(str_replace(parent_dir($source) . '/', '', $file . '/'));
                 } elseif (@is_file($file)) {
                     $zip->addFile($file, str_replace(parent_dir($source) . '/', '', $file));
                 }
             }
         } elseif (@is_file($source)) {
             $zip->addFile($source, basename($source));
         }
     }
     $num_files = $zip->numFiles;
     $zip_result = $zip->close();
     if (!$zip_result) {
         return new WP_Error('zip', "Could not properly close archive '" . $destination . "'.");
     }
     return $num_files;
 }