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


PHP ZipArchive::locateName方法代码示例

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


在下文中一共展示了ZipArchive::locateName方法的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: docx_getTextFromZippedXML

function docx_getTextFromZippedXML($archiveFile, $contentFile, $cacheFolder, $debug)
{
    // Создаёт "реинкарнацию" zip-архива...
    $zip = new \ZipArchive();
    // И пытаемся открыть переданный zip-файл
    if ($zip->open($archiveFile)) {
        @mkdir($cacheFolder);
        $zip->extractTo($cacheFolder);
        // В случае успеха ищем в архиве файл с данными
        $xml = false;
        $xml2 = false;
        $file = $contentFile;
        if (($index = $zip->locateName($file)) !== false) {
            // Если находим, то читаем его в строку
            $content = $zip->getFromIndex($index);
            // После этого подгружаем все entity и по возможности include'ы других файлов
            $xml = \DOMDocument::loadXML($content, LIBXML_NOENT | LIBXML_XINCLUDE | LIBXML_NOERROR | LIBXML_NOWARNING);
        }
        $file = 'word/_rels/document.xml.rels';
        if (($index = $zip->locateName($file)) !== false) {
            // Если находим, то читаем его в строку
            $content = $zip->getFromIndex($index);
            $xml2 = \DOMDocument::loadXML($content, LIBXML_NOENT | LIBXML_XINCLUDE | LIBXML_NOERROR | LIBXML_NOWARNING);
            //@ - https://bugs.php.net/bug.php?id=41398 Strict Standards:  Non-static method DOMDocument::loadXML() should not be called statically
        }
        $zip->close();
        return array($xml, $xml2);
    }
}
开发者ID:akiyatkin,项目名称:files,代码行数:29,代码来源:Docx.php

示例3: load

 private function load($file)
 {
     if (file_exists($file)) {
         $zip = new ZipArchive();
         if ($zip->open($file) === true) {
             //attempt to load styles:
             if (($styleIndex = $zip->locateName('word/styles.xml')) !== false) {
                 $stylesXml = $zip->getFromIndex($styleIndex);
                 $xml = simplexml_load_string($stylesXml);
                 $namespaces = $xml->getNamespaces(true);
                 $children = $xml->children($namespaces['w']);
                 foreach ($children->style as $s) {
                     $attr = $s->attributes('w', true);
                     if (isset($attr['styleId'])) {
                         $tags = array();
                         $attrs = array();
                         foreach (get_object_vars($s->rPr) as $tag => $style) {
                             $att = $style->attributes('w', true);
                             switch ($tag) {
                                 case "b":
                                     $tags[] = 'strong';
                                     break;
                                 case "i":
                                     $tags[] = 'em';
                                     break;
                                 case "color":
                                     //echo (String) $att['val'];
                                     $attrs[] = 'color:#' . $att['val'];
                                     break;
                                 case "sz":
                                     $attrs[] = 'font-size:' . $att['val'] . 'px';
                                     break;
                             }
                         }
                         $styles[(string) $attr['styleId']] = array('tags' => $tags, 'attrs' => $attrs);
                     }
                 }
                 $this->styles = $styles;
             }
             if (($index = $zip->locateName('word/document.xml')) !== false) {
                 // If found, read it to the string
                 $data = $zip->getFromIndex($index);
                 // Close archive file
                 $zip->close();
                 return $data;
             }
             $zip->close();
         } else {
             $this->errors[] = 'Could not open file.';
         }
     } else {
         $this->errors[] = 'File does not exist.';
     }
 }
开发者ID:rinteresting,项目名称:Docx-to-HTML,代码行数:54,代码来源:docx_reader.php

示例4: install_font

 public function install_font($post_title, $post)
 {
     if ($post->post_type == 'font' && isset($_REQUEST['family'])) {
         $family = $_REQUEST['family'];
         $r = wp_remote_get($this->apiurl . "familyinfo/{$family}");
         if (!is_wp_error($r)) {
             $details = json_decode($r['body']);
             $post_title = $details[0]->family_name;
             //$dir = WP_CONTENT_DIR . "/fonts/$family";
             $dir = $this->root_font_dir . "/{$family}";
             //$subdir_name = strtolower(str_replace($details[0]->style_name, '', $details[0]->fontface_name));
             // save family
             add_post_meta($post->ID, 'font-family', $family);
             if (!is_dir($dir)) {
                 mkdir($dir);
                 // download font-face kit
                 wp_remote_get("http://www.fontsquirrel.com/fontfacekit/{$family}", array('stream' => true, 'filename' => $dir . "/font-face-kit.zip"));
                 // look at font files
                 $zip = new ZipArchive();
                 $res = $zip->open($dir . "/font-face-kit.zip");
                 if ($res === TRUE) {
                     // get the stylesheet
                     $stylesheet = $zip->getFromIndex($zip->locateName('stylesheet.css', ZipArchive::FL_NODIR));
                     $fp = fopen("{$dir}/stylesheet.css", 'w');
                     fwrite($fp, $stylesheet);
                     fclose($fp);
                     // get the font files
                     preg_match_all("/([^']+webfont\\.(?:eot|woff|ttf|svg))/", $stylesheet, $matches);
                     $fontfiles = array();
                     foreach (array_unique($matches[1]) as $fontfile) {
                         $i = $zip->locateName($fontfile, ZipArchive::FL_NODIR);
                         $fp = fopen("{$dir}/{$fontfile}", 'w');
                         fwrite($fp, $zip->getFromIndex($i));
                         fclose($fp);
                     }
                     // get the font name
                     preg_match("/font-family: '([^']+)';/", $stylesheet, $matches);
                     add_post_meta($post->ID, 'font-name', $matches[1]);
                     $zip->close();
                 }
                 // download samples
                 wp_remote_get($details[0]->listing_image, array('stream' => true, 'filename' => $dir . "/listing_image.png"));
                 wp_remote_get($details[0]->sample_image, array('stream' => true, 'filename' => $dir . "/sample_image.png"));
                 wp_remote_get(str_replace('sp-720', 'sa-720x300', $details[0]->sample_image), array('stream' => true, 'filename' => $dir . "/sample_alphabet.png"));
                 wp_remote_get(str_replace('sp-720', 'para-128x200-9', $details[0]->sample_image), array('stream' => true, 'filename' => $dir . "/sample_paragraph_9.png"));
                 wp_remote_get(str_replace('sp-720', 'para-128x200-10', $details[0]->sample_image), array('stream' => true, 'filename' => $dir . "/sample_paragraph_10.png"));
                 wp_remote_get(str_replace('sp-720', 'para-202x200-12', $details[0]->sample_image), array('stream' => true, 'filename' => $dir . "/sample_paragraph_12.png"));
                 wp_remote_get(str_replace('sp-720', 'para-202x200-16', $details[0]->sample_image), array('stream' => true, 'filename' => $dir . "/sample_paragraph_16.png"));
             }
         }
     }
     return $post_title;
 }
开发者ID:1nterval,项目名称:wp-fontsquirrel,代码行数:53,代码来源:class.fontsquirrelapi.php

示例5: testCompressFolder

 public function testCompressFolder()
 {
     $files = array('releases-noNewPatch.xml', 'releases-patchsOnly.xml', 'releases.xml', 'folder/', 'folder/emptyFile', 'emptyFolder/');
     $dest = dirname(__FILE__) . '/backup/test.zip';
     $src = dirname(__FILE__) . '/sample';
     taoUpdate_helpers_Zip::compressFolder($src, $dest);
     $this->assertTrue(is_file($dest));
     $zip = new ZipArchive();
     $zip->open($dest);
     foreach ($files as $file) {
         $this->assertFalse($zip->locateName($file) === false, $file . ' not found');
     }
     $this->assertFalse($zip->locateName('.svn'));
     helpers_File::remove($dest);
     $dest = dirname(__FILE__) . '/backup/test2.zip';
     taoUpdate_helpers_Zip::compressFolder($src, $dest, true);
     $files = array('sample/releases-noNewPatch.xml', 'sample/releases-patchsOnly.xml', 'sample/releases.xml', 'sample/folder/', 'sample/folder/emptyFile', 'sample/emptyFolder/');
     $this->assertTrue(is_file($dest));
     $zip = new ZipArchive();
     $zip->open($dest);
     for ($i = 0; $i < $zip->numFiles; $i++) {
         $stat = $zip->statIndex($i);
         //cehck no .svn added in zip
         $this->assertFalse(strpos($stat['name'], '.svn') > 0);
     }
     foreach ($files as $file) {
         $this->assertFalse($zip->locateName($file) === false);
     }
     helpers_File::remove($dest);
 }
开发者ID:llecaque,项目名称:extension-tao-update,代码行数:30,代码来源:ZipTestCase.php

示例6: getListFormatting

 /**
  * grabs formatting for list styles from a related internal data file
  *
  * @param  SimpleXMLElement $numPr the list object element
  * @return array                   wrapping tags for ordered and unordered lists
  */
 private function getListFormatting($numPr)
 {
     $id = $numPr->numId->attributes('w', TRUE)['val'];
     $level = $numPr->ilvl->attributes('w', TRUE)['val'];
     if (FALSE !== ($index = $this->zip->locateName('word/numbering.xml'))) {
         $xml = $this->zip->getFromIndex($index);
         $doc = new DOMDocument();
         $doc->preserveWhiteSpace = FALSE;
         $doc->loadXML($xml);
         $xpath = new DOMXPath($doc);
         $nodes = $xpath->query('/w:numbering/w:num[@w:numId=' . $id . ']/w:abstractNumId');
         if ($nodes->length) {
             $id = $nodes->item(0)->getAttribute('w:val');
             $nodes = $xpath->query('/w:numbering/w:abstractNum[@w:abstractNumId=' . $id . ']/w:lvl[@w:ilvl=' . $level . ']/w:numFmt');
             if ($nodes->length) {
                 $listFormat = $nodes->item(0)->getAttribute('w:val');
                 if ($listFormat === 'bullet') {
                     return ['<ul>', '</ul>'];
                 } else {
                     if ($listFormat === 'decimal') {
                         return ['<ol>', '</ol>'];
                     }
                 }
             }
         }
     }
     return ['<ul class="list-unstyled">', '</ul>'];
 }
开发者ID:sophia2152,项目名称:DocX2HtmlParser,代码行数:34,代码来源:DocX2HtmlParser.php

示例7: extracttext

function extracttext($filename)
{
    //Check for extension
    //$ext = end(explode('.', $filename));
    //if its docx file
    //if($ext == 'docx')
    $dataFile = "word/document.xml";
    //else it must be odt file
    //else
    //$dataFile = "content.xml";
    //Create a new ZIP archive object
    $zip = new ZipArchive();
    // Open the archive file
    if (true === $zip->open($filename)) {
        // If successful, search for the data file in the archive
        if (($index = $zip->locateName($dataFile)) !== false) {
            // Index found! Now read it to a string
            $text = $zip->getFromIndex($index);
            // Load XML from a string
            // Ignore errors and warnings
            $xml = DOMDocument::loadXML($text, LIBXML_NOENT | LIBXML_XINCLUDE | LIBXML_NOERROR | LIBXML_NOWARNING);
            // Remove XML formatting tags and return the text
            return strip_tags($xml->saveXML());
        }
        //Close the archive file
        $zip->close();
    }
    // In case of failure return a message
    return "File not found";
}
开发者ID:richardneal,项目名称:Lexomics,代码行数:30,代码来源:uploader.php

示例8: url_stat

 public function url_stat($path, $flags)
 {
     $ret = [];
     $zippath = preg_replace('/^myzip:\\/\\//', "", $path);
     $parts = explode('#', $zippath, 2);
     if (count($parts) != 2) {
         return false;
     }
     list($zippath, $subfile) = $parts;
     $za = new \ZipArchive();
     if ($za->open($zippath) !== true) {
         return false;
     }
     $i = $za->locateName($subfile);
     if ($i === false) {
         return false;
     }
     $zst = $za->statIndex($i);
     $za->close();
     unset($za);
     foreach ([7 => 'size', 8 => 'mtime', 9 => 'mtime', 10 => 'mtime'] as $a => $b) {
         if (!isset($zst[$b])) {
             continue;
         }
         $ret[$a] = $zst[$b];
     }
     return $ret;
 }
开发者ID:DWWf,项目名称:pocketmine-plugins,代码行数:28,代码来源:MyZipStream.php

示例9: 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

示例10: getZipContent

 /**
  * Give it a path to a file and it will return
  * the contents of that file, either as xml or html
  *
  * @param string $file
  * @param bool $as_xml (optional)
  *
  * @return boolean|\DOMDocument
  */
 protected function getZipContent($file, $as_xml = true)
 {
     // Locates an entry using its name
     $index = $this->zip->locateName($file);
     if (false === $index) {
         return false;
     }
     // returns the contents using its index
     $content = $this->zip->getFromIndex($index);
     // if it's not xml, return
     if (!$as_xml) {
         return $content;
     }
     $collapsed = preg_replace('/\\s+/', '', $content);
     if (preg_match('/<!DOCTYPE/i', $collapsed)) {
         // Invalid XML: Detected use of illegal DOCTYPE
         return false;
     }
     // trouble with simplexmlelement and elements with dashes
     // (ODT's are ripe with dashes), so giving it to the DOM
     $old_value = libxml_disable_entity_loader(true);
     $xml = new \DOMDocument();
     $xml->loadXML($content, LIBXML_NOBLANKS | LIBXML_NOENT | LIBXML_NONET | LIBXML_XINCLUDE | LIBXML_NOERROR | LIBXML_NOWARNING);
     libxml_disable_entity_loader($old_value);
     return $xml;
 }
开发者ID:pressbooks,项目名称:pressbooks,代码行数:35,代码来源:class-pb-docx.php

示例11: readZippedXML

function readZippedXML($archiveFile, $dataFile)
{
    if (!class_exists('ZipArchive', false)) {
        return "ZipArchive Class Doesn't Exist.";
    }
    // Create new ZIP archive
    $zip = new ZipArchive();
    // Open received archive file
    if (true === $zip->open($archiveFile)) {
        // If done, search for the data file in the archive
        if (($index = $zip->locateName($dataFile)) !== false) {
            // If found, read it to the string
            $data = $zip->getFromIndex($index);
            // Close archive file
            $zip->close();
            // Load XML from a string
            // Skip errors and warnings
            return $data;
            //            $xml = DOMDocument::loadXML($data, LIBXML_NOENT | LIBXML_XINCLUDE | LIBXML_NOERROR | LIBXML_NOWARNING);
            //            // Return data without XML formatting tags
            //            return strip_tags($xml->saveXML());
        }
        $zip->close();
    }
    // In case of failure return empty string
    return $zip->getStatusString();
}
开发者ID:GettyScholarsWorkspace,项目名称:GettyScholarsWorkspace,代码行数:27,代码来源:docx.php

示例12: fromName

 /**
  * Create a new entry with a name
  * @param   string          $name
  * @param   \ZipArchive     $archive
  * @return  ZipArchiveEntry
  */
 public static function fromName($name, \ZipArchive $archive)
 {
     $index = $archive->locateName($name);
     if ($index === false) {
         throw new \InvalidArgumentException('Entry does not exist in the archive.');
     }
     return self::fromIndex($index, $archive);
 }
开发者ID:alexanderwanyoike,项目名称:php-compression,代码行数:14,代码来源:ZipArchiveEntry.php

示例13: offsetUnset

 /**
  * @inheritdoc
  */
 public function offsetUnset($offset)
 {
     if ($this->archive->locateName($offset) !== false) {
         $this->archive->deleteName($offset);
     } else {
         return null;
     }
 }
开发者ID:alexanderwanyoike,项目名称:php-compression,代码行数:11,代码来源:ZipArchive.php

示例14: postInstall

 public function postInstall()
 {
     User::onlyHas("template-install");
     $extract_path = Files::fullDir("upload/tmp/tpl/");
     if (file_exists($extract_path) === FALSE) {
         mkdir($extract_path, 0777, true);
     }
     $returnData = [];
     if (isset($_FILES['template'])) {
         $zip = new ZipArchive();
         $result = $zip->open($_FILES['template']['tmp_name']);
         if ($result === TRUE) {
             if ($zip->locateName('install.php') !== false) {
                 // extract files
                 $zip->extractTo($extract_path);
                 //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/");
                 // get template settings
                 $config = (require_once $extract_path . 'install.php');
                 if (isset($config['app']) && file_exists(Files::fullDir('apps/' . $config['app'] . '/'))) {
                     $template_newfolder = Files::fullDir('apps/' . $config['app'] . '/views/templates/' . $config['name'] . '/');
                     if (isset($config['name']) && file_exists($template_newfolder) === FALSE) {
                         $template_folder = $extract_path . $config['name'] . '/';
                         if (file_exists($template_folder)) {
                             mkdir($template_newfolder);
                             rename($template_folder, $template_newfolder);
                             $returnData['message'] = varlang('tpl-succeful');
                             $returnData['message_type'] = 'alert-success';
                         } else {
                             $returnData['message'] = varlang('template-not-found-in-zip');
                             $returnData['message_type'] = 'alert-danger';
                         }
                     } else {
                         $returnData['message'] = varlang('undefined-template-name-or-already-exists');
                         $returnData['message_type'] = 'alert-danger';
                     }
                 } else {
                     $returnData['message'] = varlang('undefined-app-name');
                     $returnData['message_type'] = 'alert-danger';
                 }
                 File::deleteDirectory($extract_path);
             } else {
                 $returnData['message'] = varlang('installphp-is-required');
                 $returnData['message_type'] = 'alert-danger';
             }
             $zip->close();
         } else {
             $returnData['message'] = varlang('invalid-zip');
             $returnData['message_type'] = 'alert-danger';
         }
     } else {
         $returnData['message'] = varlang('invalid-file');
         $returnData['message_type'] = 'alert-danger';
     }
     return Redirect::to('template')->with($returnData);
 }
开发者ID:vcorobceanu,项目名称:WebAPL,代码行数:56,代码来源:TemplateController.php

示例15: hasSharedStrings

 /**
  * Returns whether the XLSX file contains a shared strings XML file
  *
  * @return bool
  */
 public function hasSharedStrings()
 {
     $hasSharedStrings = false;
     $zip = new \ZipArchive();
     if ($zip->open($this->filePath) === true) {
         $hasSharedStrings = $zip->locateName(self::SHARED_STRINGS_XML_FILE_PATH) !== false;
         $zip->close();
     }
     return $hasSharedStrings;
 }
开发者ID:janeklb,项目名称:moodle,代码行数:15,代码来源:SharedStringsHelper.php


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