当前位置: 首页>>代码示例>>PHP>>正文


PHP ZipArchive::addEmptyDir方法代码示例

本文整理汇总了PHP中ZipArchive::addEmptyDir方法的典型用法代码示例。如果您正苦于以下问题:PHP ZipArchive::addEmptyDir方法的具体用法?PHP ZipArchive::addEmptyDir怎么用?PHP ZipArchive::addEmptyDir使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ZipArchive的用法示例。


在下文中一共展示了ZipArchive::addEmptyDir方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: zipData

function zipData($source, $destination)
{
    if (extension_loaded('zip')) {
        if (file_exists($source)) {
            $zip = new ZipArchive();
            if ($zip->open($destination, ZIPARCHIVE::CREATE)) {
                $source = realpath($source);
                if (is_dir($source)) {
                    $iterator = new RecursiveDirectoryIterator($source);
                    // skip dot files while iterating
                    $iterator->setFlags(RecursiveDirectoryIterator::SKIP_DOTS);
                    $files = new RecursiveIteratorIterator($iterator, RecursiveIteratorIterator::SELF_FIRST);
                    foreach ($files as $file) {
                        $file = realpath($file);
                        if (is_dir($file)) {
                            $zip->addEmptyDir(str_replace($source . '/', '', $file . '/'));
                        } else {
                            if (is_file($file)) {
                                $zip->addFromString(str_replace($source . '/', '', $file), file_get_contents($file));
                            }
                        }
                    }
                } else {
                    if (is_file($source)) {
                        $zip->addFromString(basename($source), file_get_contents($source));
                    }
                }
            }
            echo $destination . ' zip: successfully...';
            echo "\n";
            return $zip->close();
        }
    }
    return false;
}
开发者ID:phn007,项目名称:BuildHtml,代码行数:35,代码来源:zip.php

示例2: writeToFile

 public function writeToFile($filename)
 {
     @unlink($filename);
     //if the zip already exists, overwrite it
     $zip = new ZipArchive();
     if (empty($this->sheets_meta)) {
         self::log("Error in " . __CLASS__ . "::" . __FUNCTION__ . ", no worksheets defined.");
         return;
     }
     if (!$zip->open($filename, ZipArchive::CREATE)) {
         self::log("Error in " . __CLASS__ . "::" . __FUNCTION__ . ", unable to create zip.");
         return;
     }
     $zip->addEmptyDir("docProps/");
     $zip->addFromString("docProps/app.xml", self::buildAppXML());
     $zip->addFromString("docProps/core.xml", self::buildCoreXML());
     $zip->addEmptyDir("_rels/");
     $zip->addFromString("_rels/.rels", self::buildRelationshipsXML());
     $zip->addEmptyDir("xl/worksheets/");
     foreach ($this->sheets_meta as $sheet_meta) {
         $zip->addFile($sheet_meta['filename'], "xl/worksheets/" . $sheet_meta['xmlname']);
     }
     if (!empty($this->shared_strings)) {
         $zip->addFile($this->writeSharedStringsXML(), "xl/sharedStrings.xml");
         //$zip->addFromString("xl/sharedStrings.xml",     self::buildSharedStringsXML() );
     }
     $zip->addFromString("xl/workbook.xml", self::buildWorkbookXML());
     $zip->addFile($this->writeStylesXML(), "xl/styles.xml");
     //$zip->addFromString("xl/styles.xml"           , self::buildStylesXML() );
     $zip->addFromString("[Content_Types].xml", self::buildContentTypesXML());
     $zip->addEmptyDir("xl/_rels/");
     $zip->addFromString("xl/_rels/workbook.xml.rels", self::buildWorkbookRelsXML());
     $zip->close();
 }
开发者ID:henryavila,项目名称:itop,代码行数:34,代码来源:xlsxwriter.class.php

示例3: folderToZip

 /**
  * @param $folder
  * @param $zipFile
  * @param $exclusiveLength
  * @param $messager
  */
 private static function folderToZip($folder, \ZipArchive &$zipFile, $exclusiveLength, callable $messager = null)
 {
     $handle = opendir($folder);
     while (false !== ($f = readdir($handle))) {
         if ($f != '.' && $f != '..') {
             $filePath = "{$folder}/{$f}";
             // Remove prefix from file path before add to zip.
             $localPath = substr($filePath, $exclusiveLength);
             if (in_array($f, static::$ignoreFolders)) {
                 continue;
             } elseif (in_array($localPath, static::$ignorePaths)) {
                 $zipFile->addEmptyDir($f);
                 continue;
             }
             if (is_file($filePath)) {
                 $zipFile->addFile($filePath, $localPath);
                 $messager && $messager(['type' => 'progress', 'percentage' => false, 'complete' => false]);
             } elseif (is_dir($filePath)) {
                 // Add sub-directory.
                 $zipFile->addEmptyDir($localPath);
                 static::folderToZip($filePath, $zipFile, $exclusiveLength, $messager);
             }
         }
     }
     closedir($handle);
 }
开发者ID:indigo423,项目名称:blog.no42.org,代码行数:32,代码来源:ZipBackup.php

示例4: Zip

function Zip($source, $destination){
  if (extension_loaded('zip') === true) {
    if (file_exists($source) === true) {
      $zip = new ZipArchive();

      if ($zip->open($destination, ZIPARCHIVE::CREATE) === true) {
        $source = realpath($source);

        if (is_dir($source) === true) {
          
          $zip->addEmptyDir('core/export/');
          $zip->addEmptyDir('core/import/');
          $zip->addEmptyDir('core/cache/');
          $zip->addEmptyDir('archive/archives/');
          
          $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source), RecursiveIteratorIterator::SELF_FIRST);
          foreach ($files as $file) {
            if (is_dir($file) === true && !strpos($file,'.') && !strpos($file,'/core/cache/')) {
              $zip->addEmptyDir(str_replace($source . '/', '', $file . '/'));
            }
            else if (is_file($file) === true && !strpos($file,'/core/cache/') && !strpos($file,'/archive/archives/')) {
              $zip->addFromString(str_replace($source . '/', '', $file), file_get_contents($file));
            }
          }
        }
        else if (is_file($source) === true) {
          $zip->addFromString(basename($source), file_get_contents($source));
        }
        return $zip->close();
      }
    }
  }

  return false;
}
开发者ID:Adeptx,项目名称:adeptx_core,代码行数:35,代码来源:create_backup.php

示例5: zipDirectory

 /**
  * 方法その1
  * @param unknown $dir
  * @param unknown $file
  * @param string $root
  * @return boolean
  */
 function zipDirectory($dir, $file, $root = "")
 {
     $zip = new ZipArchive();
     $res = $zip->open($file, ZipArchive::CREATE);
     if ($res) {
         // $rootが指定されていればその名前のフォルダにファイルをまとめる
         if ($root != "") {
             $zip->addEmptyDir($root);
             $root .= DIRECTORY_SEPARATOR;
         }
         $baseLen = mb_strlen($dir);
         $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir, FilesystemIterator::SKIP_DOTS | FilesystemIterator::KEY_AS_PATHNAME | FilesystemIterator::CURRENT_AS_FILEINFO), RecursiveIteratorIterator::SELF_FIRST);
         $list = array();
         foreach ($iterator as $pathname => $info) {
             $localpath = $root . mb_substr($pathname, $baseLen);
             // debug($localpath);
             if ($info->isFile()) {
                 // $zip->addFile($pathname,$filenameonly );
                 $zip->addFile($pathname, $localpath);
             } else {
                 $res = $zip->addEmptyDir($localpath);
             }
         }
         $zip->close();
     } else {
         return false;
     }
 }
开发者ID:shranes,项目名称:hics,代码行数:35,代码来源:ZipComponent.php

示例6: zipFiles

 /**
  * Zip files
  *
  * @param string $targetDir Target dir path
  * @param array  $files     Files to zip
  *
  * @throws \Exception
  */
 private function zipFiles($targetDir, $files)
 {
     $zip = new \ZipArchive();
     $zipName = pathinfo($files[0], PATHINFO_FILENAME);
     $zipPath = FileSystem::getUniquePath($targetDir . DIRECTORY_SEPARATOR . $zipName . ".zip");
     if ($zip->open($zipPath, \ZipArchive::CREATE)) {
         foreach ($files as $file) {
             $path = $targetDir . DIRECTORY_SEPARATOR . $file;
             if (is_dir($path)) {
                 $zip->addEmptyDir($file);
                 foreach (Finder::find("*")->from($path) as $item) {
                     $name = $file . DIRECTORY_SEPARATOR . substr_replace($item->getPathname(), "", 0, strlen($path) + 1);
                     if ($item->isDir()) {
                         $zip->addEmptyDir($name);
                     } else {
                         $zip->addFile($item->getRealPath(), $name);
                     }
                 }
             } else {
                 $zip->addFile($path, $file);
             }
         }
         $zip->close();
     } else {
         throw new \Exception("Can not create ZIP archive '{$zipPath}' from '{$targetDir}'.");
     }
 }
开发者ID:ixtrum,项目名称:file-manager-plugins,代码行数:35,代码来源:Zip.php

示例7: zipCreate

 /**
  * Authors: http://stackoverflow.com/questions/1334613/how-to-recursively-zip-a-directory-in-php thx for that
  * @param $source
  * @param $destination
  * @param bool $include_dir
  * @param array $additionalIgnoreFiles
  * @return bool
  */
 private function zipCreate($source, $destination, $include_dir = false, $additionalIgnoreFiles = array())
 {
     // Ignore "." and ".." folders by default
     $defaultIgnoreFiles = array('.', '..');
     // include more files to ignore
     $ignoreFiles = array_merge($defaultIgnoreFiles, $additionalIgnoreFiles);
     if (!extension_loaded('zip') || !file_exists($source)) {
         return false;
     }
     if (file_exists($destination)) {
         unlink($destination);
     }
     $zip = new \ZipArchive();
     if (!$zip->open($destination, \ZIPARCHIVE::CREATE)) {
         return false;
     }
     $source = str_replace('\\', '/', realpath($source));
     if (is_dir($source) === true) {
         $files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($source), \RecursiveIteratorIterator::SELF_FIRST);
         if ($include_dir) {
             $arr = explode("/", $source);
             $maindir = $arr[count($arr) - 1];
             $source = "";
             for ($i = 0; $i < count($arr) - 1; $i++) {
                 $source .= '/' . $arr[$i];
             }
             $source = substr($source, 1);
             $zip->addEmptyDir($maindir);
         }
         foreach ($files as $file) {
             $file = str_replace('\\', '/', $file);
             // purposely ignore files that are irrelevant
             if (in_array(substr($file, strrpos($file, '/') + 1), $ignoreFiles)) {
                 continue;
             }
             $file = realpath($file);
             if (is_dir($file) === true) {
                 $zip->addEmptyDir(str_replace($source . '/', '', $file . '/'));
             } else {
                 if (is_file($file) === true) {
                     $zip->addFromString(str_replace($source . '/', '', $file), file_get_contents($file));
                 }
             }
         }
     } else {
         if (is_file($source) === true) {
             $zip->addFromString(basename($source), file_get_contents($source));
         }
     }
     $zip->close();
     return true;
 }
开发者ID:ZerGabriel,项目名称:ffcms,代码行数:60,代码来源:dumper.class.php

示例8: zip

 /**
  * 
  * zip a directory or some file
  * @param String/Array $directoryORfilesarray
  * @return boolean
  * @throws Exception
  */
 public function zip($directoryORfilesarray = '.')
 {
     //backup old zip file
     if (file_exists($this->zipName)) {
         if (!rename($this->zipName, $this->zipName . '.old')) {
             throw new Exception("Cannot backup {$this->zipName} File, check permissions!");
         }
     }
     //create zip file
     if ($this->ZipArchive->open($this->zipName, ZIPARCHIVE::CREATE) !== TRUE) {
         throw new Exception("Cannot create {$this->zipName} File, check permissions and directory!");
     }
     //zip a directory
     if (is_string($directoryORfilesarray) && is_dir($directoryORfilesarray)) {
         $dir = rtrim($directoryORfilesarray, '/');
         //get all file
         $this->_getAllFiles($dir, $this->allFiles);
         //add file to zip file
         foreach ($this->allFiles as $file) {
             if (is_dir($file)) {
                 if ($dir == '.') {
                     $file = substr($file, 2);
                 }
                 $this->ZipArchive->addEmptyDir($file);
             }
             if (is_file($file)) {
                 if ($dir == '.') {
                     $file = substr($file, 2);
                 }
                 $this->ZipArchive->addFile($file);
             }
         }
     }
     //zip some files
     if (is_array($directoryORfilesarray)) {
         foreach ($directoryORfilesarray as $file) {
             if (!file_exists($file)) {
                 throw new Exception("{$file} is not exists!");
             }
             if (is_dir($file)) {
                 $this->ZipArchive->addEmptyDir($file);
             }
             if (is_file($file)) {
                 $this->ZipArchive->addFile($file);
             }
         }
     }
     return $this->ZipArchive->close();
 }
开发者ID:rock-op,项目名称:snippet,代码行数:56,代码来源:TX_Zip.php

示例9: exportZip

 function exportZip($fileName)
 {
     $queue = [['', $this->rootFolder]];
     $zip = new ZipArchive();
     $zip->open($fileName, ZIPARCHIVE::CREATE);
     if ($this->rootFolder->isProxy) {
         while ($queue) {
             list($path, $folder) = array_shift($queue);
             foreach ($folder->getItemArray() as $item) {
                 if ($item instanceof Folder) {
                     if ($path) {
                         $subpath = "{$path}/{$item->name}";
                     } else {
                         $subpath = $item->name;
                     }
                     $queue[] = [$subpath, $item];
                     $zip->addEmptyDir($subpath);
                 } elseif ($item instanceof File) {
                     if ($path) {
                         $subpath = "{$path}/{$item->name}";
                     } else {
                         $subpath = $item->name;
                     }
                     $content = $item->getContent();
                     $zip->addFromString($subpath, $content['content']);
                 }
             }
         }
     }
     $zip->close();
 }
开发者ID:ufosky-server,项目名称:Gvirila,代码行数:31,代码来源:FileSystem.php

示例10: create

 /**
  * 
  * @return boolean
  * @throws Kohana_Exception
  */
 public function create()
 {
     if (!extension_loaded('zip') === true) {
         throw new Kohana_Exception('Extension "zip" not loaded');
     }
     $zip = new ZipArchive();
     if ($zip->open(BACKUP_PLUGIN_FOLDER . 'filesystem-' . date('YmdHis') . '.zip', ZIPARCHIVE::CREATE) === true) {
         $sources = array(PUBLICPATH, PLUGPATH, LAYOUTS_SYSPATH, SNIPPETS_SYSPATH);
         foreach ($sources as $source) {
             if (is_dir($source) === true) {
                 $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source), RecursiveIteratorIterator::SELF_FIRST);
                 foreach ($files as $file) {
                     $file = realpath($file);
                     if (is_dir($file) === true) {
                         $zip->addEmptyDir(str_replace(DOCROOT, '', $file . DIRECTORY_SEPARATOR));
                     } else {
                         if (is_file($file) === true) {
                             $zip->addFromString(str_replace(DOCROOT, '', $file), file_get_contents($file));
                         }
                     }
                 }
             }
         }
         $zip->close();
         return TRUE;
     }
     return FALSE;
 }
开发者ID:ZerGabriel,项目名称:cms-1,代码行数:33,代码来源:filesystem.php

示例11: zipFolder

 /**
  * Compresses a given folder to a ZIP file
  *
  * @param string $inputFolder the source folder that is to be zipped
  * @param string $zipOutputFile the destination file that the ZIP is to be written to
  * @return boolean whether this process was successful or not
  */
 function zipFolder($inputFolder, $zipOutputFile)
 {
     if (!extension_loaded('zip') || !file_exists($inputFolder)) {
         return false;
     }
     $zip = new ZipArchive();
     if (!$zip->open($zipOutputFile, ZIPARCHIVE::CREATE)) {
         return false;
     }
     $inputFolder = str_replace('\\', '/', realpath($inputFolder));
     if (is_dir($inputFolder) === true) {
         $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($inputFolder, FilesystemIterator::SKIP_DOTS | FilesystemIterator::UNIX_PATHS), RecursiveIteratorIterator::SELF_FIRST);
         foreach ($files as $file) {
             $file = str_replace('\\', '/', $file);
             if (is_dir($file) === true) {
                 $dirName = str_replace($inputFolder . '/', '', $file . '/');
                 $zip->addEmptyDir($dirName);
             } else {
                 if (is_file($file) === true) {
                     $fileName = str_replace($inputFolder . '/', '', $file);
                     $zip->addFromString($fileName, file_get_contents($file));
                 }
             }
         }
     } else {
         if (is_file($inputFolder) === true) {
             $zip->addFromString(basename($inputFolder), file_get_contents($inputFolder));
         }
     }
     return $zip->close();
 }
开发者ID:jeckel420,项目名称:Localize,代码行数:38,代码来源:File_IO.php

示例12: zip

 /**
  * Zip Action
  *
  * @return bool
  */
 public function zip()
 {
     $recursive = [];
     foreach ($this->files as $name => $file) {
         $realPath = $file->getRealPath();
         //echo $name . '<br />';
         $baseName = basename($name);
         if ($baseName == '..' || $baseName == '.') {
             $folder = trim($realPath, '.');
             if ($this->checkNotContains($folder) == false) {
                 $recursive[] = ['zFolder' => 1, 'fileRoot' => null, 'fileDes' => null, 'folder' => str_replace($this->baseDir, '', $folder)];
             }
         } else {
             if ($realPath && $this->checkNotContains($realPath) == false) {
                 $recursive[] = ['zFile' => 1, 'fileRoot' => $realPath, 'fileDes' => str_replace($this->baseDir, '', $realPath), 'folder' => null];
             }
         }
     }
     $recursive = array_reverse($recursive);
     foreach ($recursive as $r) {
         if ($r['fileDes']) {
             $this->zip->addFile($r['fileRoot'], $r['fileDes']);
         } else {
             $this->zip->addEmptyDir($r['folder']);
         }
     }
     return $this->zip->close();
 }
开发者ID:kimthangatm,项目名称:zcms,代码行数:33,代码来源:ZZip.php

示例13: generateArtifact

    /**
     * Creates the distribution artifact.
     *
     * @param \Generator $emoteGenerator Contains a generator which will yield objects
     *     of type GbsLogistics\Emotes\EmoteBundle\Entity\Emote .
     * @return ReleaseArtifact
     */
    public function generateArtifact(\Generator $emoteGenerator)
    {
        $zipDir = $this->getNamespace();
        $outputFilename = tempnam(sys_get_temp_dir(), $this->getNamespace());
        $zip = new \ZipArchive();
        if (!$zip->open($outputFilename)) {
            throw new \RuntimeException(sprintf('Can\'t open file %s for writing', $outputFilename));
        }
        $zip->addEmptyDir($zipDir);
        $header = $this->generateHeader();
        $themeFile = sprintf(<<<EOTXT
Name=%s
Description=%s
Icon=%s
Author=%s

[default]

EOTXT
, $header->getName(), $header->getDescription(), $header->getIcon(), $header->getAuthor());
        /** @var Emote $emote */
        foreach ($emoteGenerator as $emote) {
            $themeFile .= $this->generateEmoteEntry($emote);
            $zip->addFile($this->dataStorage->getImageSourcePath($emote->getPath()), $zipDir . '/' . $emote->getPath());
        }
        $zip->addFromString($zipDir . '/theme', $themeFile);
        $zip->close();
        $artifact = new ReleaseArtifact();
        $artifact->setNamespace($this->getNamespace());
        $artifact->setPath($outputFilename);
        $artifact->setName($this->getName());
        return $artifact;
    }
开发者ID:jlwitthuhn,项目名称:emotepack,代码行数:40,代码来源:PidginRelease.php

示例14: zip

 public static function zip($source, $destination, $exclude = '')
 {
     if (extension_loaded('zip') === true) {
         if (file_exists($source) === true) {
             $zip = new ZipArchive();
             if ($zip->open($destination, ZIPARCHIVE::CREATE) === true) {
                 $source = realpath($source);
                 if (is_dir($source) === true) {
                     $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source), RecursiveIteratorIterator::SELF_FIRST);
                     foreach ($files as $file) {
                         if (strpos($file, $exclude) == 0) {
                             $file = realpath($file);
                             if (is_dir($file) === true) {
                                 $zip->addEmptyDir(str_replace($source . DIRECTORY_SEPARATOR, '', $file . DIRECTORY_SEPARATOR));
                             } else {
                                 if (is_file($file) === true) {
                                     $zip->addFile($file, str_replace($source . DIRECTORY_SEPARATOR, '', $file));
                                 }
                             }
                         }
                     }
                 } else {
                     if (is_file($source) === true) {
                         $zip->addFile($source, basename($source));
                         //$zip->addFromString(basename($source), file_get_contents($source));
                     }
                 }
             }
             return $zip->close();
         }
     }
     return false;
 }
开发者ID:hkhateb,项目名称:linet3,代码行数:33,代码来源:Zipper.php

示例15: zip

 /**
  * Creates a zip file from a file or a folder recursively without a full nested folder structure inside the zip file
  * Based on: http://stackoverflow.com/a/1334949/3073849
  * @param      string   $source      The path of the folder you want to zip
  * @param      string   $destination The path of the zip file you want to create
  * @return     bool     Returns TRUE on success or FALSE on failure.
  */
 public static function zip($source, $destination)
 {
     if (!extension_loaded('zip') || !file_exists($source)) {
         return false;
     }
     $zip = new ZipArchive();
     if (!$zip->open($destination, ZIPARCHIVE::CREATE)) {
         return false;
     }
     $source = str_replace('\\', '/', realpath($source));
     if (is_dir($source)) {
         foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source, FilesystemIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST) as $path) {
             $path = str_replace('\\', '/', $path);
             $path = realpath($path);
             if (is_dir($path)) {
                 $zip->addEmptyDir(str_replace($source . '/', '', $path . '/'));
             } elseif (is_file($path)) {
                 $zip->addFile($path, str_replace($source . '/', '', $path));
             }
         }
     } elseif (is_file($source)) {
         $zip->addFile($source, basename($source));
     }
     return $zip->close();
 }
开发者ID:html2wp,项目名称:simple-file-manager,代码行数:32,代码来源:simple-file-manager.php


注:本文中的ZipArchive::addEmptyDir方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。