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


PHP ZipArchive::getNameIndex方法代码示例

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


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

示例1: testZipArchive

 /**
  * Test all methods
  *
  * @param string $zipClass
  * @covers ::<public>
  */
 public function testZipArchive($zipClass = 'ZipArchive')
 {
     // Preparation
     $existingFile = __DIR__ . '/../_files/documents/sheet.xls';
     $zipFile = __DIR__ . '/../_files/documents/ziptest.zip';
     $destination1 = __DIR__ . '/../_files/documents/extract1';
     $destination2 = __DIR__ . '/../_files/documents/extract2';
     @mkdir($destination1);
     @mkdir($destination2);
     Settings::setZipClass($zipClass);
     $object = new ZipArchive();
     $object->open($zipFile, ZipArchive::CREATE);
     $object->addFile($existingFile, 'xls/new.xls');
     $object->addFromString('content/string.txt', 'Test');
     $object->close();
     $object->open($zipFile);
     // Run tests
     $this->assertEquals(0, $object->locateName('xls/new.xls'));
     $this->assertFalse($object->locateName('blablabla'));
     $this->assertEquals('Test', $object->getFromName('content/string.txt'));
     $this->assertEquals('Test', $object->getFromName('/content/string.txt'));
     $this->assertFalse($object->getNameIndex(-1));
     $this->assertEquals('content/string.txt', $object->getNameIndex(1));
     $this->assertFalse($object->extractTo('blablabla'));
     $this->assertTrue($object->extractTo($destination1));
     $this->assertTrue($object->extractTo($destination2, 'xls/new.xls'));
     $this->assertFalse($object->extractTo($destination2, 'blablabla'));
     // Cleanup
     $this->deleteDir($destination1);
     $this->deleteDir($destination2);
     @unlink($zipFile);
 }
开发者ID:HaiLeader,项目名称:quizz,代码行数:38,代码来源:ZipArchiveTest.php

示例2: _extractByPhpLib

 /**
  * ZipArchive クラスによる展開
  *
  * @param $source
  * @param $target
  * @return bool
  */
 protected function _extractByPhpLib($source, $target)
 {
     if ($this->Zip->open($source) === true && $this->Zip->extractTo($target)) {
         $archivePath = $this->Zip->getNameIndex(0);
         $archivePathAry = explode(DS, $archivePath);
         $this->topArchiveName = $archivePathAry[0];
         return true;
     } else {
         return false;
     }
 }
开发者ID:baserproject,项目名称:basercms,代码行数:18,代码来源:BcZip.php

示例3: getToC

function getToC($archive)
{
    $toc = array();
    if (endsWith($archive, ".cbz")) {
        $zip = new ZipArchive();
        if ($zip->open($archive)) {
            for ($i = 0; $i < $zip->numFiles; $i++) {
                if (endsWith($zip->getNameIndex($i), '.jpg') || endsWith($zip->getNameIndex($i), '.gif') || endsWith($zip->getNameIndex($i), '.png')) {
                    $toc[] = $zip->getNameIndex($i);
                }
            }
            natcasesort($toc);
            $toc = array_values($toc);
            $zip->close();
        }
    } else {
        if (endsWith($archive, ".cbr")) {
            $rar = RarArchive::open($archive);
            if ($rar !== false) {
                $rar_entries = $rar->getEntries();
                for ($i = 0; $i < count($rar_entries); $i++) {
                    if (endsWith($rar_entries[$i]->getName(), '.jpg') || endsWith($rar_entries[$i]->getName(), '.gif') || endsWith($rar_entries[$i]->getName(), '.png')) {
                        $toc[] = $rar_entries[$i]->getName();
                    }
                }
                natcasesort($toc);
                $toc = array_values($toc);
                $rar->close();
            }
        }
    }
    return $toc;
}
开发者ID:auroris,项目名称:Web-Comic-Book-Archive-Reader,代码行数:33,代码来源:ComicService.php

示例4: basename

 function test_forProjectJson()
 {
     $req = $this->requester;
     $result = $req->request("Data.Download.project", ['robertblackwell', 'project1', ['format' => 'json', 'template' => ['zip' => "{organization_name}_{project_name}", 'file' => 'strings.{format}', 'dir' => "{format}/{language_code}"]]]);
     //		print_r($result);
     $this->assertGoodResponse($result, 200);
     $arr = $this->extractApiResult($result);
     $url = $arr['url'];
     /*
      * @TODO - fix
      */
     $zipFileName = __DIR__ . "/temp-json.gzip";
     $this->requester->getFile($url, $zipFileName);
     $this->assertTrue(file_exists($zipFileName));
     $zip = new \ZipArchive();
     if (!file_exists($zipFileName)) {
         print "gzip file does not exist\n";
     }
     $res = $zip->open($zipFileName);
     $dir_name = $zip->getNameIndex(0);
     $archive_name = basename($url) . "-dir/";
     $archive_name = basename($url) . "/";
     print "\n archive_name {$archive_name}\n";
     print "\n index 1 " . $zip->getNameIndex(1) . "\n";
     //		$this->assertTrue($dir_name === "robertblackwell_project1");
 }
开发者ID:robertblackwell,项目名称:srmn,代码行数:26,代码来源:FileDownloadTest.php

示例5: action

 public function action($parent)
 {
     $c = $parent->config;
     $util = new Utility();
     if (strpos($_POST['path'], '/') === 0 || strpos($_POST['path'], '../') !== false || strpos($_POST['path'], './') === 0) {
         $this->r = array('wrong path', 400);
         return;
     }
     $path = $c['current_path'] . $_POST['path'];
     $info = pathinfo($path);
     $base_folder = $c['current_path'] . $util->fix_dirname($_POST['path']) . "/";
     switch ($info['extension']) {
         case "zip":
             $zip = new \ZipArchive();
             if ($zip->open($path) === true) {
                 //make all the folders
                 for ($i = 0; $i < $zip->numFiles; $i++) {
                     $OnlyFileName = $zip->getNameIndex($i);
                     $FullFileName = $zip->statIndex($i);
                     if (substr($FullFileName['name'], -1, 1) == "/") {
                         $util->create_folder($base_folder . $FullFileName['name']);
                     }
                 }
                 //unzip into the folders
                 for ($i = 0; $i < $zip->numFiles; $i++) {
                     $OnlyFileName = $zip->getNameIndex($i);
                     $FullFileName = $zip->statIndex($i);
                     if (!(substr($FullFileName['name'], -1, 1) == "/")) {
                         $fileinfo = pathinfo($OnlyFileName);
                         if (in_array(strtolower($fileinfo['extension']), $ext)) {
                             copy('zip://' . $path . '#' . $OnlyFileName, $base_folder . $FullFileName['name']);
                         }
                     }
                 }
                 $zip->close();
             } else {
                 $this->r = array('Could not extract. File might be corrupt.', 500);
                 return;
             }
             break;
         case "gz":
             $p = new \PharData($path);
             $p->decompress();
             // creates files.tar
             break;
         case "tar":
             // unarchive from the tar
             $phar = new \PharData($path);
             $phar->decompressFiles();
             $files = array();
             $util->check_files_extensions_on_phar($phar, $files, '', $ext);
             $phar->extractTo($current_path . fix_dirname($_POST['path']) . "/", $files, true);
             break;
         default:
             $this->r = array('This extension is not supported. Valid: zip, gz, tar.', 400);
             return;
             break;
     }
 }
开发者ID:Kingtreemonkey,项目名称:FileManager,代码行数:59,代码来源:Extract.php

示例6: listContents

 /**
  * {@inheritdoc}
  */
 public function listContents()
 {
     $files = array();
     for ($i = 0; $i < $this->zip->numFiles; $i++) {
         $files[] = $this->zip->getNameIndex($i);
     }
     return $files;
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:11,代码来源:Zip.php

示例7: add

 /**
  * Add method
  *
  * @return void Redirects on successful add, renders view otherwise.
  */
 public function add()
 {
     if ($this->request->is('post')) {
         $mc = 0;
         $mc1 = 0;
         switch ($this->request->data('Archive')['type']) {
             case "application/x-rar":
                 break;
             case "application/octet-stream":
             case "application/x-zip":
             case "application/x-zip-compressed":
             case "application/zip":
                 $zip = new \ZipArchive();
                 $zip->open($this->request->data('Archive')['tmp_name']);
                 for ($i = 0; $i < $zip->numFiles; $i++) {
                     $filepath = pathinfo($zip->getNameIndex($i));
                     if (isset($filepath['extension']) && $filepath['extension'] == 'dm' && $filepath['dirname'] == '.') {
                         $mod = $this->Mods->newEntity();
                         $mod = $this->Mods->patchEntity($mod, $this->request->data);
                         $mod->dmname = $filepath['basename'];
                         if (!file_exists('tmp/mods/')) {
                             mkdir('tmp/mods/', 0777, true);
                         }
                         $zip->extractTo(WWW_ROOT . 'tmp/mods/', $zip->getNameIndex($i));
                         $fd = fopen(WWW_ROOT . 'tmp/mods/' . $zip->getNameIndex($i), 'r');
                         $hash = crc32(fread($fd, 99999999));
                         $mod->crc32 = $hash;
                         $clash = $this->Mods->find('all')->where(['crc32' => $hash])->first();
                         if ($clash) {
                             $mc1++;
                         } else {
                             fclose($fd);
                             if ($this->Mods->save($mod)) {
                                 $mc++;
                             } else {
                             }
                         }
                     }
                 }
                 $zip->close();
                 break;
             case "7z":
                 break;
         }
         $this->Flash->success(__($mc . ' mods found and saved.' . ($mc1 == 0 ? "" : ' ' . $mc1 . " mods had already been uploaded")));
         return $this->redirect(['action' => 'index']);
     }
     $mod = $this->Mods->newEntity();
     $this->set(compact('mod'));
     $this->set('_serialize', ['mod']);
 }
开发者ID:Moggers,项目名称:blitzserver,代码行数:56,代码来源:ModsController.php

示例8: beforeSave

 public function beforeSave($event, $entity, $options)
 {
     if ($entity->get('Archive')['tmp_name'] != '') {
         switch ($entity->get('Archive')['type']) {
             case "application/x-rar":
                 break;
             case "application/zip":
             case "application/octet-stream":
             case "application/x-zip-compressed":
             case "application/x-zip":
                 $zip = new \ZipArchive();
                 $zip->open($entity->get('Archive')['tmp_name']);
                 for ($i = 0; $i < $zip->numFiles; $i++) {
                     $filepath = pathinfo($zip->getNameIndex($i));
                     if ($filepath['basename'] == $entity->get('dmname')) {
                         $fd = fopen(WWW_ROOT . 'tmp/mods/' . $zip->getNameIndex($i), 'r');
                         if ($fd) {
                             rewind($fd);
                             while (($line = fgets($fd)) !== false) {
                                 if (strpos($line, '#disableoldnations') !== false) {
                                     $entity->set('disableoldnations', 1);
                                 }
                                 $arr = explode(' ', $line);
                                 switch ($arr[0]) {
                                     case '--':
                                         break;
                                     case '#version':
                                         $entity->set('version', trim(substr($line, strlen('#version '))));
                                         break;
                                     case '#description':
                                         $entity->set('description', trim(str_replace('"', '', substr($line, strlen('#description ')))));
                                         break;
                                     case '#modname':
                                         $entity->set('name', trim(str_replace('"', '', substr($line, strlen('#modname ')))));
                                         break;
                                     case '#icon':
                                         $entity->set('icon', trim(str_Replace('"', '', substr($line, strlen('#icon ')))));
                                         break;
                                 }
                             }
                             fclose($fd);
                         }
                         $zip->close();
                         return true;
                     }
                 }
                 break;
         }
         return true;
     }
 }
开发者ID:Moggers,项目名称:blitzserver,代码行数:51,代码来源:ModsTable.php

示例9: getFiles

 /**
  * @inheritDoc
  */
 public function getFiles($only_root = false)
 {
     $files = array();
     $zip = new \ZipArchive();
     if ($zip->open($this->file)) {
         $num_files = $zip->numFiles;
         $counter = 0;
         for ($i = 0; $i < $num_files; $i++) {
             $file = $zip->getNameIndex($i);
             $parent_directories = $this->getParentDirStack($file);
             if ($only_root) {
                 if (empty($parent_directories)) {
                     $files[$file] = $counter++;
                 } else {
                     $files[end($parent_directories)] = $counter++;
                 }
             } else {
                 $files[$file] = $counter++;
                 foreach ($parent_directories as $parent_dir_path) {
                     $files[$parent_dir_path] = $counter++;
                 }
             }
         }
         $files = array_flip($files);
         $zip->close();
     }
     $zip = null;
     sort($files);
     return $files;
 }
开发者ID:ambient-lounge,项目名称:site,代码行数:33,代码来源:ZipArchiveReader.php

示例10: postInstall

 public function postInstall()
 {
     User::onlyHas("modules-view");
     if (isset($_FILES['module'])) {
         $zip = new ZipArchive();
         $result = $zip->open($_FILES['module']['tmp_name']);
         if ($result) {
             // get install, frontent and backend files
             $files = array();
             for ($i = 0; $i < $zip->numFiles; $i++) {
                 $files[] = $zip->getNameIndex($i);
             }
             if (!in_array('install.php', $files)) {
                 echo "INSTALL.PHP is required";
                 return;
             }
             // extract files
             $zip->extractTo($_SERVER['DOCUMENT_ROOT'] . "/tmp/zip/");
             //rename($_SERVER['DOCUMENT_ROOT'] . "/tmp/zip/backend/", $_SERVER['DOCUMENT_ROOT'] . "/apps/backend/modules/");
             //rename($_SERVER['DOCUMENT_ROOT'] . "/tmp/zip/frontend/", $_SERVER['DOCUMENT_ROOT'] . "/apps/frontend/modules/");
             require_once $_SERVER['DOCUMENT_ROOT'] . '/tmp/zip/install.php';
             array_map('unlink', glob($_SERVER['DOCUMENT_ROOT'] . "/tmp/zip/*"));
             $zip->close();
         } else {
         }
     }
     Redirect::to('module');
     $this->layout = null;
 }
开发者ID:vcorobceanu,项目名称:WebAPL,代码行数:29,代码来源:ModuleController.php

示例11: setUploadFile

 public function setUploadFile($ulFileName = "")
 {
     if ($ulFileName) {
         //URL to existing file
         if (file_exists($ulFileName)) {
             $pos = strrpos($ulFileName, "/");
             if (!$pos) {
                 $pos = strrpos($ulFileName, "\\");
             }
             $this->uploadFileName = substr($ulFileName, $pos + 1);
             //$this->outputMsg($this->uploadFileName;
             copy($ulFileName, $this->uploadTargetPath . $this->uploadFileName);
         }
     } elseif (array_key_exists('uploadfile', $_FILES)) {
         $this->uploadFileName = $_FILES['uploadfile']['name'];
         move_uploaded_file($_FILES['uploadfile']['tmp_name'], $this->uploadTargetPath . $this->uploadFileName);
     }
     if (file_exists($this->uploadTargetPath . $this->uploadFileName) && substr($this->uploadFileName, -4) == ".zip") {
         $zip = new ZipArchive();
         $zip->open($this->uploadTargetPath . $this->uploadFileName);
         $zipFile = $this->uploadTargetPath . $this->uploadFileName;
         $this->uploadFileName = $zip->getNameIndex(0);
         $zip->extractTo($this->uploadTargetPath);
         $zip->close();
         unlink($zipFile);
     }
 }
开发者ID:jphilip124,项目名称:Symbiota,代码行数:27,代码来源:TaxaUpload.php

示例12: getPluginMeta

 /**
  * Retrieve plugin info from meta.json in zip
  * @param $zipPath
  * @return bool|mixed
  * @throws CakeException
  */
 public function getPluginMeta($zipPath)
 {
     $Zip = new \ZipArchive();
     if ($Zip->open($zipPath) === true) {
         $search = 'config/meta.json';
         $indexJson = $Zip->locateName('meta.json', \ZipArchive::FL_NODIR);
         if ($indexJson === false) {
             throw new Exception(__d('spider', 'Invalid meta information in archive'));
         } else {
             $fileName = $Zip->getNameIndex($indexJson);
             $fileJson = json_decode($Zip->getFromIndex($indexJson));
             if (empty($fileJson->name)) {
                 throw new Exception(__d('spider', 'Invalid meta.json or missing plugin name'));
             } else {
                 $pluginRootPath = str_replace($search, '', $fileName);
                 $fileJson->rootPath = $pluginRootPath;
             }
         }
         $Zip->close();
         if (!isset($fileJson) || empty($fileJson)) {
             throw new Exception(__d('spider', 'Invali meta.json'));
         }
         return $fileJson;
     } else {
         throw new CakeException(__d('spider', 'Invalid zip archive'));
     }
     return false;
 }
开发者ID:mohammadsaleh,项目名称:spider,代码行数:34,代码来源:PluginInstaller.php

示例13: extractTo

 public function extractTo($extractPath, $files = null)
 {
     $fs = new FileSystem();
     $ds = DIRECTORY_SEPARATOR;
     for ($i = 0; $i < $this->numFiles; $i++) {
         $oldName = parent::getNameIndex($i);
         $newName = mb_convert_encoding($this->getNameIndex($i), 'ISO-8859-1', 'CP850,UTF-8');
         //we cheat a little because we can't tell wich name the extracted part should have
         //so we put it a directory wich share it's name
         $tmpDir = $extractPath . $ds . '__claro_zip_hack_' . $oldName;
         parent::extractTo($tmpDir, parent::getNameIndex($i));
         //now we move the content of the directory and we put the good name on it.
         foreach ($iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($tmpDir, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST) as $item) {
             if ($item->isFile()) {
                 $fs->mkdir(dirname($extractPath . $ds . $oldName));
                 $fs->rename($item->getPathname(), $extractPath . $ds . $oldName);
             }
         }
     }
     //we remove our 'trash here'
     $iterator = new \DirectoryIterator($extractPath);
     foreach ($iterator as $item) {
         if (strpos($item->getFilename(), '_claro_zip_hack')) {
             $fs->rmdir($item->getRealPath(), true);
         }
     }
 }
开发者ID:ngydat,项目名称:CoreBundle,代码行数:27,代码来源:ZipArchive.php

示例14: setHash

 /**
  * Sets the hash that is used to uniquely identify this plugin
  */
 public function setHash()
 {
     $archiveName = $this->getFilenameOnFilestore();
     $zip = new ZipArchive();
     $result = $zip->open($archiveName);
     if ($result !== true) {
         return false;
     }
     for ($i = 0; $i < $zip->numFiles; $i++) {
         $filename = $zip->getNameIndex($i);
         if (stripos($filename, 'manifest.xml') !== false) {
             $manifest = $zip->getFromIndex($i);
             $id = substr($filename, 0, strpos($filename, '/'));
             break;
         }
     }
     $zip->close();
     if (!isset($manifest)) {
         return false;
     }
     try {
         $manifest = new ElggPluginManifest($manifest);
         $author = $manifest->getAuthor();
         $version = $manifest->getVersion();
         $this->hash = md5($id . $version . $author);
     } catch (Exception $e) {
         // skip invalid manifests
     }
 }
开发者ID:lorea,项目名称:Hydra-dev,代码行数:32,代码来源:PluginRelease.php

示例15: expand

 /**
  * Expand archive
  *
  * @param   bool  $cleanup  Whether or not to clean up after expansion (i.e. removing known OS files, etc...)
  * @return  bool
  */
 public function expand($cleanup = true)
 {
     // Create local tmp copy of the archive that's being expanded
     $temp = Manager::getTempPath($this->getName());
     $this->copy($temp);
     $zip = new \ZipArchive();
     // Open the temp archive (we use the absolute path because we're on the local filesystem)
     if ($zip->open($temp->getAbsolutePath()) === true) {
         // We don't actually have to extract the archive, we can just read out of it and copy over to the original location
         for ($i = 0; $i < $zip->numFiles; $i++) {
             $filename = $zip->getNameIndex($i);
             $entity = Entity::fromPath($this->getParent() . '/' . $filename, $this->getAdapter());
             if ($entity->isFile()) {
                 // Open
                 $item = fopen('zip://' . $temp->getAbsolutePath() . '#' . $filename, 'r');
                 // Write stream
                 $entity->putStream($item);
                 // Close
                 fclose($item);
             } else {
                 // Create the directory
                 $entity->create();
             }
         }
         // Clean up
         $zip->close();
         $temp->delete();
         return parent::expand($cleanup);
     }
     return false;
 }
开发者ID:mined-gatech,项目名称:hubzero-cms,代码行数:37,代码来源:Zip.php


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