本文整理汇总了PHP中ZipArchive::open方法的典型用法代码示例。如果您正苦于以下问题:PHP ZipArchive::open方法的具体用法?PHP ZipArchive::open怎么用?PHP ZipArchive::open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ZipArchive
的用法示例。
在下文中一共展示了ZipArchive::open方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: save
/**
* Save PHPExcel to file
*
* @param string $pFileName
* @throws Exception
*/
public function save($pFilename = null)
{
if (!is_null($this->_spreadSheet)) {
// Garbage collect...
foreach ($this->_spreadSheet->getAllSheets() as $sheet) {
$sheet->garbageCollect();
}
// Create new ZIP file and open it for writing
$objZip = new ZipArchive();
// Try opening the ZIP file
if ($objZip->open($pFilename, ZIPARCHIVE::OVERWRITE) !== true) {
if ($objZip->open($pFilename, ZIPARCHIVE::CREATE) !== true) {
throw new Exception("Could not open " . $pFilename . " for writing.");
}
}
// Add media
$sheetCount = $this->_spreadSheet->getSheetCount();
for ($i = 0; $i < $sheetCount; ++$i) {
for ($j = 0; $j < $this->_spreadSheet->getSheet($i)->getDrawingCollection()->count(); ++$j) {
if ($this->_spreadSheet->getSheet($i)->getDrawingCollection()->offsetGet($j) instanceof PHPExcel_Worksheet_BaseDrawing) {
$imgTemp = $this->_spreadSheet->getSheet($i)->getDrawingCollection()->offsetGet($j);
$objZip->addFromString('media/' . $imgTemp->getFilename(), file_get_contents($imgTemp->getPath()));
}
}
}
// Add phpexcel.xml to the document, which represents a PHP serialized PHPExcel object
$objZip->addFromString('phpexcel.xml', $this->_writeSerialized($this->_spreadSheet, $pFilename));
// Close file
if ($objZip->close() === false) {
throw new Exception("Could not close zip file {$pFilename}.");
}
} else {
throw new Exception("PHPExcel object unassigned.");
}
}
示例2: unzip_content
function unzip_content()
{
$zip = new ZipArchive();
if (file_exists('application.zip')) {
$res = $zip->open('application.zip');
if ($res === TRUE) {
echo '<p>Unzipped Application <i class="fa fa-check-circle-o"></i></p>';
$zip->extractTo('./');
$zip->close();
unlink('application.zip');
} else {
echo '<p>Could not unzip application.zip <i class="fa fa-times-circle-o"></i></p>';
}
} else {
echo '<p>Application already unzipped <i class="fa fa-check-circle-o"></i></p>';
}
new_line();
if (file_exists('content.zip')) {
$res = $zip->open('content.zip');
if ($res === TRUE) {
echo '<p>Unzipped Content <i class="fa fa-check-circle-o"></i></p>';
$zip->extractTo('./');
$zip->close();
unlink('content.zip');
} else {
echo '<p>Could not unzip content.zip <i class="fa fa-times-circle-o"></i></p>';
}
} else {
echo '<p>Content already unzipped <i class="fa fa-check-circle-o"></i></p>';
}
new_line();
}
示例3: 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);
}
示例4: extractArchive
private function extractArchive()
{
$this->archive->close();
$this->archive->open($this->archive_path);
$this->archive->extractTo($this->extraction_path);
$this->archive->close();
}
示例5: upload
/**
* Upload component
*
* @requires component package file,
*
* @return bool;
*/
public function upload()
{
$archive = new ZipArchive();
$data_dir = ossn_get_userdata('tmp/components');
if (!is_dir($data_dir)) {
mkdir($data_dir, 0755, true);
}
$zip = $_FILES['com_file'];
$newfile = "{$data_dir}/{$zip['name']}";
if (move_uploaded_file($zip['tmp_name'], $newfile)) {
if ($archive->open($newfile) === TRUE) {
$archive->extractTo($data_dir);
//make community components works on installer #394
$validate = $archive->statIndex(0);
$validate = str_replace('/', '', $validate['name']);
$archive->close();
if (is_dir("{$data_dir}/{$validate}") && is_file("{$data_dir}/{$validate}/ossn_com.php") && is_file("{$data_dir}/{$validate}/ossn_com.xml")) {
$archive->open($newfile);
$archive->extractTo(ossn_route()->com);
$archive->close();
$this->newCom($validate);
OssnFile::DeleteDir($data_dir);
return true;
}
}
}
return false;
}
示例6: upload
/**
* Upload component
*
* @requires component package file,
*
* @return bool;
*/
public function upload()
{
$archive = new ZipArchive();
$data_dir = ossn_get_userdata('tmp/components');
if (!is_dir($data_dir)) {
mkdir($data_dir, 0755, true);
}
$zip = $_FILES['com_file'];
$newfile = "{$data_dir}/{$zip['name']}";
if (move_uploaded_file($zip['tmp_name'], $newfile)) {
if ($archive->open($newfile) === TRUE) {
$archive->extractTo($data_dir);
$archive->close();
$validate = pathinfo($zip['name'], PATHINFO_FILENAME);
if (is_file("{$data_dir}/{$validate}/ossn_com.php") && is_file("{$data_dir}/{$validate}/ossn_com.xml")) {
$archive->open($newfile);
$archive->extractTo(ossn_route()->com);
$archive->close();
$this->newCom($validate);
OssnFile::DeleteDir($data_dir);
return true;
}
}
}
return false;
}
示例7: _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;
}
}
示例8: fillZipWithFileContents
/**
* Add all file and string contents to zip file.
*
* @param string $zipFileUrl
*/
private function fillZipWithFileContents($zipFileUrl)
{
$this->zip->open($zipFileUrl, \ZipArchive::CREATE);
$this->finalizeSheet();
$this->finalizeStyles();
$this->finalizeDefaultXmls();
}
示例9: __construct
/**
* Constructs a Zip object.
*
* @param string $file_path
* The full system path of the archive to manipulate. Only local files
* are supported. If the file does not yet exist, it will be created if
* appropriate.
*
* @throws \Drupal\Core\Archiver\ArchiverException
*/
public function __construct($file_path)
{
$this->zip = new \ZipArchive();
if ($this->zip->open($file_path) !== TRUE) {
throw new ArchiverException(t('Cannot open %file_path', array('%file_path' => $file_path)));
}
}
示例10: save
/**
* Save PhpPresentation to file
*
* @param string $pFilename
* @throws \Exception
*/
public function save($pFilename)
{
if (empty($pFilename)) {
throw new \Exception("Filename is empty.");
}
if (!is_null($this->presentation)) {
// Create new ZIP file and open it for writing
$objZip = new \ZipArchive();
// Try opening the ZIP file
if ($objZip->open($pFilename, \ZipArchive::CREATE) !== true) {
if ($objZip->open($pFilename, \ZipArchive::OVERWRITE) !== true) {
throw new \Exception("Could not open " . $pFilename . " for writing.");
}
}
// Add media
$slideCount = $this->presentation->getSlideCount();
for ($i = 0; $i < $slideCount; ++$i) {
for ($j = 0; $j < $this->presentation->getSlide($i)->getShapeCollection()->count(); ++$j) {
if ($this->presentation->getSlide($i)->getShapeCollection()->offsetGet($j) instanceof AbstractDrawing) {
$imgTemp = $this->presentation->getSlide($i)->getShapeCollection()->offsetGet($j);
$objZip->addFromString('media/' . $imgTemp->getFilename(), file_get_contents($imgTemp->getPath()));
}
}
}
// Add PhpPresentation.xml to the document, which represents a PHP serialized PhpPresentation object
$objZip->addFromString('PhpPresentation.xml', $this->writeSerialized($this->presentation, $pFilename));
// Close file
if ($objZip->close() === false) {
throw new \Exception("Could not close zip file {$pFilename}.");
}
} else {
throw new \Exception("PhpPresentation object unassigned.");
}
}
示例11: __construct
public function __construct($archive_path)
{
$this->archive = new \ZipArchive();
$this->archive_path = $archive_path;
if ($this->archive->open($this->archive_path, \ZipArchive::CREATE) !== true) {
throw new ArchiveException('Cannot create zip archive: ' . $this->archive_path);
}
}
示例12: __construct
/**
* Crea un archivo ZIP
*/
public function __construct()
{
# create new zip opbject
$this->_zip = new ZipArchive();
# create a temp file & open it
$this->_tempfile = tempnam('.', '');
$this->_zip->open($this->_tempfile, ZipArchive::CREATE);
}
示例13: __construct
/**
* ZipArchiveCreator constructor
*
* @param string $file Path to archive
* @throws \Exception
*/
public function __construct($file)
{
$this->zip = new \ZipArchive();
$this->file = $file;
if ($this->zip->open($this->file, \ZipArchive::CREATE) !== true) {
throw new \Exception('Unable create archive');
}
}
示例14: zipOpen
/**
* @param string $filePath
* @return $this
* @throws Exception\Zip\FileOpenException
*/
private function zipOpen($filePath)
{
if ($code = $this->zip->open($filePath) !== true) {
throw new Exception\Zip\FileOpenException($filePath, $code);
}
$this->filePath = $filePath;
return $this;
}
示例15: __construct
/**
* Constructor
*
* @param string $filename Name of the .zip archive
* @throws Exception
*/
public function __construct($filename)
{
$this->filename = $filename;
$this->ziparchive = new ZipArchive();
if ($this->ziparchive->open($filename) !== true) {
throw new Exception('Error opening ' . $filename);
}
}