本文整理汇总了PHP中ZipArchive::getFromName方法的典型用法代码示例。如果您正苦于以下问题:PHP ZipArchive::getFromName方法的具体用法?PHP ZipArchive::getFromName怎么用?PHP ZipArchive::getFromName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ZipArchive
的用法示例。
在下文中一共展示了ZipArchive::getFromName方法的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);
}
示例2: extractMetaData
/**
* Extract metadata from document
*
* @param \ZipArchive $package ZipArchive AbstractOpenXML package
* @return array Key-value pairs containing document meta data
*/
protected function extractMetaData(\ZipArchive $package)
{
// Data holders
$coreProperties = array();
// Prevent php from loading remote resources
$loadEntities = libxml_disable_entity_loader(true);
// Read relations and search for core properties
$relations = simplexml_load_string($package->getFromName("_rels/.rels"));
// Restore entity loader state
libxml_disable_entity_loader($loadEntities);
foreach ($relations->Relationship as $rel) {
if ($rel["Type"] == self::SCHEMA_COREPROPERTIES) {
// Found core properties! Read in contents...
$contents = simplexml_load_string($package->getFromName(dirname($rel["Target"]) . "/" . basename($rel["Target"])));
foreach ($contents->children(self::SCHEMA_DUBLINCORE) as $child) {
$coreProperties[$child->getName()] = (string) $child;
}
foreach ($contents->children(self::SCHEMA_COREPROPERTIES) as $child) {
$coreProperties[$child->getName()] = (string) $child;
}
foreach ($contents->children(self::SCHEMA_DUBLINCORETERMS) as $child) {
$coreProperties[$child->getName()] = (string) $child;
}
}
}
return $coreProperties;
}
示例3: __construct
/**
* Object constructor
*
* @param string $fileName
* @param boolean $storeContent
*/
private function __construct($fileName, $storeContent)
{
// Document data holders
$documentBody = array();
$coreProperties = array();
// Open OpenXML package
$package = new ZipArchive();
$package->open($fileName);
// Read relations and search for officeDocument
$relations = simplexml_load_string($package->getFromName('_rels/.rels'));
foreach ($relations->Relationship as $rel) {
if ($rel["Type"] == Zend_Search_Lucene_Document_OpenXml::SCHEMA_OFFICEDOCUMENT) {
// Found office document! Read in contents...
$contents = simplexml_load_string($package->getFromName($this->absoluteZipPath(dirname($rel['Target']) . '/' . basename($rel['Target']))));
$contents->registerXPathNamespace('w', Zend_Search_Lucene_Document_Docx::SCHEMA_WORDPROCESSINGML);
$paragraphs = $contents->xpath('//w:body/w:p');
foreach ($paragraphs as $paragraph) {
$runs = $paragraph->xpath('.//w:r/*[name() = "w:t" or name() = "w:br"]');
if ($runs === false) {
// Paragraph doesn't contain any text or breaks
continue;
}
foreach ($runs as $run) {
if ($run->getName() == 'br') {
// Break element
$documentBody[] = ' ';
} else {
$documentBody[] = (string) $run;
}
}
// Add space after each paragraph. So they are not bound together.
$documentBody[] = ' ';
}
break;
}
}
// Read core properties
$coreProperties = $this->extractMetaData($package);
// Close file
$package->close();
// Store filename
$this->addField(Zend_Search_Lucene_Field::Text('filename', $fileName, 'UTF-8'));
// Store contents
if ($storeContent) {
$this->addField(Zend_Search_Lucene_Field::Text('body', implode('', $documentBody), 'UTF-8'));
} else {
$this->addField(Zend_Search_Lucene_Field::UnStored('body', implode('', $documentBody), 'UTF-8'));
}
// Store meta data properties
foreach ($coreProperties as $key => $value) {
$this->addField(Zend_Search_Lucene_Field::Text($key, $value, 'UTF-8'));
}
// Store title (if not present in meta data)
if (!isset($coreProperties['title'])) {
$this->addField(Zend_Search_Lucene_Field::Text('title', $fileName, 'UTF-8'));
}
}
示例4: __construct
/**
* Create a new Template Object
*
* @param string $strFilename
*/
public function __construct($strFilename)
{
$path = dirname($strFilename);
$this->_tempFileName = $path . DIRECTORY_SEPARATOR . time() . '.docx';
copy($strFilename, $this->_tempFileName);
// Copy the source File to the temp File
$this->_objZip = new ZipArchive();
$this->_objZip->open($this->_tempFileName);
$this->_documentXML = $this->_objZip->getFromName('word/document.xml');
}
示例5: retrieveResponse
protected function retrieveResponse()
{
$response = $this->initResponse();
if (strpos($this->fileStem, '.zip') !== false) {
if (!class_exists('ZipArchive')) {
throw new KurogoException("class ZipArchive (php-zip) not available");
}
$response->setContext('zipped', true);
$zip = new ZipArchive();
if (strpos($this->fileStem, 'http') === 0 || strpos($this->fileStem, 'ftp') === 0) {
$tmpFile = Kurogo::tempFile();
copy($this->fileStem, $tmpFile);
$zip->open($tmpFile);
} else {
$zip->open($this->fileStem);
}
// locate valid shapefile components
$shapeNames = array();
for ($i = 0; $i < $zip->numFiles; $i++) {
if (preg_match('/(.+)\\.(shp|dbf|prj)$/', $zip->getNameIndex($i), $matches)) {
$shapeName = $matches[1];
$extension = $matches[2];
if (!isset($shapeNames[$shapeName])) {
$shapeNames[$shapeName] = array();
}
$shapeNames[$shapeName][] = $extension;
}
}
$responseData = array();
foreach ($shapeNames as $shapeName => $extensions) {
if (in_array('dbf', $extensions) && in_array('shp', $extensions)) {
$fileData = array('dbf' => $zip->getFromName("{$shapeName}.dbf"), 'shp' => $zip->getFromName("{$shapeName}.shp"));
if (in_array('prj', $extensions)) {
$prjData = $zip->getFromName("{$shapeName}.prj");
$fileData['projection'] = new MapProjection($prjData);
}
$responseData[$shapeName] = $fileData;
}
}
$response->setResponse($responseData);
} elseif (realpath_exists("{$this->fileStem}.shp") && realpath_exists("{$this->fileStem}.dbf")) {
$response->setContext('zipped', false);
$response->setContext('shp', "{$this->fileStem}.shp");
$response->setContext('dbf', "{$this->fileStem}.dbf");
if (realpath_exists("{$this->fileStem}.prj")) {
$prjData = file_get_contents("{$this->fileStem}.prj");
$response->setContext('projection', new MapProjection($prjData));
}
} else {
throw new KurogoDataException("Cannot find {$this->fileStem}");
}
return $response;
}
示例6: parseFile
public function parseFile($filename)
{
if (strpos($filename, '.zip') !== false) {
if (!class_exists('ZipArchive')) {
throw new KurogoException("class ZipArchive (php-zip) not available");
}
$zip = new ZipArchive();
$zip->open($filename);
// locate valid shapefile components
$shapeNames = array();
for ($i = 0; $i < $zip->numFiles; $i++) {
if (preg_match('/(.+)\\.(shp|dbf|prj)$/', $zip->getNameIndex($i), $matches)) {
$shapeName = $matches[1];
$extension = $matches[2];
if (!isset($shapeNames[$shapeName])) {
$shapeNames[$shapeName] = array();
}
$shapeNames[$shapeName][] = $extension;
}
}
$this->dbfParser = new DBase3FileParser();
foreach ($shapeNames as $shapeName => $extensions) {
if (in_array('dbf', $extensions) && in_array('shp', $extensions)) {
$this->setContents($zip->getFromName("{$shapeName}.shp"));
$contents = $zip->getFromName("{$shapeName}.dbf");
if (!$contents) {
throw new KurogoDataException("could not read {$shapeName}.dbf");
}
$this->dbfParser->setContents($zip->getFromName("{$shapeName}.dbf"));
$this->dbfParser->setup();
if (in_array('prj', $extensions)) {
$prjData = $zip->getFromName("{$shapeName}.prj");
$this->mapProjection = new MapProjection($prjData);
}
$this->doParse();
}
}
} elseif (realpath_exists("{$filename}.shp") && realpath_exists("{$filename}.dbf")) {
$this->setFilename("{$filename}.shp");
$this->dbfParser = new DBase3FileParser();
$this->dbfParser->setFilename("{$filename}.dbf");
$this->dbfParser->setup();
$prjFile = $filename . '.prj';
if (realpath_exists($prjFile)) {
$prjData = file_get_contents($prjFile);
$this->mapProjection = new MapProjection($prjData);
}
$this->doParse();
} else {
throw new KurogoDataException("Cannot find {$filename}");
}
return $this->features;
}
示例7: __construct
/**
* Create a new Template Object
*
* @param string $strFilename
*/
public function __construct($strFilename)
{
$this->_tempFileName = tempnam(sys_get_temp_dir(), '');
if ($this->_tempFileName !== false) {
// Copy the source File to the temp File
if (!copy($strFilename, $this->_tempFileName)) {
throw new PHPWord_Exception('Could not copy the template from ' . $strFilename . ' to ' . $this->_tempFileName . '.');
}
$this->_objZip = new ZipArchive();
$this->_objZip->open($this->_tempFileName);
$this->_documentXML = $this->_objZip->getFromName('word/document.xml');
} else {
throw new PHPWord_Exception('Could not create temporary file with unique name in the default temporary directory.');
}
}
示例8: getMimeType
/**
* @return string
*/
public function getMimeType()
{
if (!CommonFile::fileExists($this->getZipFileOut())) {
throw new \Exception('File ' . $this->getZipFileOut() . ' does not exist');
}
$oArchive = new \ZipArchive();
$oArchive->open($this->getZipFileOut());
if (!function_exists('getimagesizefromstring')) {
$uri = 'data://application/octet-stream;base64,' . base64_encode($oArchive->getFromName($this->getZipFileIn()));
$image = getimagesize($uri);
} else {
$image = getimagesizefromstring($oArchive->getFromName($this->getZipFileIn()));
}
return image_type_to_mime_type($image[2]);
}
示例9: loadShapeDrawing
/**
* Read Shape Drawing
*
* @param \DOMElement $oNodeFrame
*/
protected function loadShapeDrawing(\DOMElement $oNodeFrame)
{
// Core
$oShape = new Gd();
$oShape->getShadow()->setVisible(false);
$oNodeImage = $this->oXMLReader->getElement('draw:image', $oNodeFrame);
if ($oNodeImage) {
if ($oNodeImage->hasAttribute('xlink:href')) {
$sFilename = $oNodeImage->getAttribute('xlink:href');
// svm = StarView Metafile
if (pathinfo($sFilename, PATHINFO_EXTENSION) == 'svm') {
return;
}
$imageFile = $this->oZip->getFromName($sFilename);
if (!empty($imageFile)) {
$oShape->setImageResource(imagecreatefromstring($imageFile));
}
}
}
$oShape->setName($oNodeFrame->hasAttribute('draw:name') ? $oNodeFrame->getAttribute('draw:name') : '');
$oShape->setDescription($oNodeFrame->hasAttribute('draw:name') ? $oNodeFrame->getAttribute('draw:name') : '');
$oShape->setResizeProportional(false);
$oShape->setWidth($oNodeFrame->hasAttribute('svg:width') ? (int) round(CommonDrawing::centimetersToPixels(substr($oNodeFrame->getAttribute('svg:width'), 0, -2))) : '');
$oShape->setHeight($oNodeFrame->hasAttribute('svg:height') ? (int) round(CommonDrawing::centimetersToPixels(substr($oNodeFrame->getAttribute('svg:height'), 0, -2))) : '');
$oShape->setResizeProportional(true);
$oShape->setOffsetX($oNodeFrame->hasAttribute('svg:x') ? (int) round(CommonDrawing::centimetersToPixels(substr($oNodeFrame->getAttribute('svg:x'), 0, -2))) : '');
$oShape->setOffsetY($oNodeFrame->hasAttribute('svg:y') ? (int) round(CommonDrawing::centimetersToPixels(substr($oNodeFrame->getAttribute('svg:y'), 0, -2))) : '');
if ($oNodeFrame->hasAttribute('draw:style-name')) {
$keyStyle = $oNodeFrame->getAttribute('draw:style-name');
if (isset($this->arrayStyles[$keyStyle])) {
$oShape->setShadow($this->arrayStyles[$keyStyle]['shadow']);
}
}
$this->oPhpPresentation->getActiveSlide()->addShape($oShape);
}
示例10: __construct
/**
* Create a new Template Object
*
* @param string $strFilename
*/
public function __construct($strFilename)
{
$path = dirname($strFilename);
$i = 0;
do {
$this->_tempFileName = $path . "/" . time() . $i++ . '.docx';
} while (file_exists($this->_tempFileName));
copy($strFilename, $this->_tempFileName);
// Copy the source File to the temp File
$this->_objZip = new ZipArchive();
$this->_objZip->open($this->_tempFileName);
$this->_documentXML = $this->_objZip->getFromName('word/document.xml');
/**FIX: 2011-06-11 Anthon S Litvinenko <a.litvinenko@web50.ru>
Replace tags between Values names */
$this->_documentXML = preg_replace_callback('|\\$\\{[^}]*}|', create_function('$matches', 'return strip_tags($matches[0]);'), $this->_documentXML);
}
示例11: reload
function reload($user)
{
$lastfacts = DB::get()->val("SELECT value FROM options WHERE name='facts' and grouping = 'misc'");
if ($lastfacts < mktime(0, 0, 0)) {
DB::get()->query("SELECT * FROM drawers WHERE indexed = 'facts'");
$users = DB::get()->col("SELECT id FROM users");
$zip = new ZipArchive();
if ($zip->open(dirname(__FILE__) . '/facts.zip') === TRUE) {
$facts = explode("\n", $zip->getFromName('facts.txt'));
$zip->close();
$fact = '<div class="factoidtext">' . $facts[date('z')] . '</div>';
} else {
$content = file_get_contents('http://www.mentalfloss.com/amazingfactgenerator/?p=' . date('z'));
$content = SimpleHTML::str_get_html($content);
$fact = '<div class="factoidtext">FAIL:' . $content->find('.amazing_fact_body p', 0)->innertext . '</div>';
}
$msg = '<a href="#" class="close" onclick="return closedrawer({$drawer_id});">close this drawer</a>' . $fact;
foreach ($users as $user_id) {
DB::get()->query("INSERT INTO drawers (user_id, message, indexed, cssclass) VALUES (:user_id, :msg, 'facts', 'factoid');", array('user_id' => $user_id, 'msg' => $msg));
}
DB::get()->query("DELETE FROM options WHERE name = 'facts' AND grouping = 'misc'");
DB::get()->query("INSERT INTO options (name, grouping, value) VALUES ('facts', 'misc', :value);", array('value' => mktime(0, 0, 0)));
}
return $user;
}
示例12: getContentXml
/**
* Retrieves the "content.xml" from the ODS file
*
* @return string The XML from "content.xml"
*/
public function getContentXml()
{
if (!$this->odsResource instanceof \ZipArchive) {
throw new \Exception('No ODS file opened!');
}
return $this->odsResource->getFromName('content.xml');
}
示例13: docxTemplate
public function docxTemplate($filepath = false, $templates = false, $output = false)
{
if ($filepath === false || $templates === false || $output === false) {
return false;
}
if (file_exists($output)) {
unlink($output);
}
copy($filepath, $output);
if (!file_exists($output)) {
die('File not found.');
}
$zip = new ZipArchive();
if (!$zip->open($output)) {
die('File not open.');
}
$documentXml = $zip->getFromName('word/document.xml');
$rekeys = array_keys($templates);
for ($i = 0; $i < count($templates); $i++) {
$reg = '';
$reg .= substr($rekeys[$i], 0, 1);
for ($i2 = 1; $i2 < strlen($rekeys[$i]); $i2++) {
$reg .= '(<.*?>)*+' . substr($rekeys[$i], $i2, 1);
}
$reg = '#' . str_replace(array('#', '{', '[', ']', '}'), array('#', '{', '[', ']', '}'), $reg) . '#';
$documentXml = preg_replace($reg, $templates[$rekeys[$i]], $documentXml);
print '->' . $reg . '<br/>';
}
$zip->deleteName('word/document.xml');
$zip->addFromString('word/document.xml', $documentXml);
$zip->close();
}
示例14: render
/**
* @return \PhpOffice\Common\Adapter\Zip\ZipInterface
*/
public function render()
{
for ($i = 0; $i < $this->getDrawingHashTable()->count(); ++$i) {
$shape = $this->getDrawingHashTable()->getByIndex($i);
if ($shape instanceof Drawing) {
$imagePath = $shape->getPath();
if (strpos($imagePath, 'zip://') !== false) {
$imagePath = substr($imagePath, 6);
$imagePathSplitted = explode('#', $imagePath);
$imageZip = new \ZipArchive();
$imageZip->open($imagePathSplitted[0]);
$imageContents = $imageZip->getFromName($imagePathSplitted[1]);
$imageZip->close();
unset($imageZip);
} else {
$imageContents = file_get_contents($imagePath);
}
$this->getZip()->addFromString('ppt/media/' . str_replace(' ', '_', $shape->getIndexedFilename()), $imageContents);
} elseif ($shape instanceof MemoryDrawing) {
ob_start();
call_user_func($shape->getRenderingFunction(), $shape->getImageResource());
$imageContents = ob_get_contents();
ob_end_clean();
$this->getZip()->addFromString('ppt/media/' . str_replace(' ', '_', $shape->getIndexedFilename()), $imageContents);
}
}
return $this->getZip();
}
示例15: extractMetaData
/**
* Extract metadata from document
*
* @param ZipArchive $package ZipArchive OpenXML package
* @return array Key-value pairs containing document meta data
*/
protected function extractMetaData(ZipArchive $package)
{
// Data holders
$coreProperties = array();
// Read relations and search for core properties
$relations = simplexml_load_string($package->getFromName("_rels/.rels"));
foreach ($relations->Relationship as $rel) {
if ($rel["Type"] == Zend_Search_Lucene_Document_OpenXml::SCHEMA_COREPROPERTIES) {
// Found core properties! Read in contents...
$contents = simplexml_load_string(
$package->getFromName(dirname($rel["Target"]) . "/" . basename($rel["Target"]))
);
foreach ($contents->children(Zend_Search_Lucene_Document_OpenXml::SCHEMA_DUBLINCORE) as $child) {
$coreProperties[$child->getName()] = (string)$child;
}
foreach ($contents->children(Zend_Search_Lucene_Document_OpenXml::SCHEMA_COREPROPERTIES) as $child) {
$coreProperties[$child->getName()] = (string)$child;
}
foreach ($contents->children(Zend_Search_Lucene_Document_OpenXml::SCHEMA_DUBLINCORETERMS) as $child) {
$coreProperties[$child->getName()] = (string)$child;
}
}
}
return $coreProperties;
}