本文整理汇总了PHP中ZipArchive::statName方法的典型用法代码示例。如果您正苦于以下问题:PHP ZipArchive::statName方法的具体用法?PHP ZipArchive::statName怎么用?PHP ZipArchive::statName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ZipArchive
的用法示例。
在下文中一共展示了ZipArchive::statName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addFolder
/**
* Adds a folder to the archive
* @param string $path The folder which will be copied into the archive
* @param string $name The entry name
* @return $this
* @throws
*/
public function addFolder($path, $name = null)
{
$fs = new Filesystem();
//check the folder exists
if (!is_dir($path)) {
throw new \InvalidArgumentException("Folder \"{$path}\" not found.");
}
$path = rtrim($path, '\\//');
//set the default name
if (is_null($name)) {
$name = basename($path);
if ($name == '.') {
$name = basename(dirname($path));
}
}
// @see http://us.php.net/manual/en/ziparchive.addfile.php#89813
// @see http://stackoverflow.com/questions/4620205/php-ziparchive-corrupt-in-windows
$name = str_replace('\\', '/', ltrim($name, '\\/'));
if (!empty($name) && $this->archive->statName($name) === false) {
if ($this->archive->addEmptyDir($name) === false) {
throw new \RuntimeException("Unable to add folder \"{$path}\" to ZIP archive as \"{$name}\".");
}
}
//** I had to use \DirectoryIterator instead of \deit\filesystem\Finder because I kept hitting the directory not empty when trying to remove files after this method
$it = new \FilesystemIterator($path);
foreach ($it as $p) {
if (empty($name)) {
$n = $fs->getRelativePath($p->getPathname(), $path);
} else {
$n = $name . '/' . $fs->getRelativePath($p->getPathname(), $path);
}
$this->add($p->getPathname(), $n);
}
return $this;
}
示例2: remplace_image
public function remplace_image($search, $urlImage)
{
/* recherche des images dans le document
* /word/media
*/
if (!file_exists($urlImage)) {
return "RI : pb urlImage.";
}
$name = 'word/media/' . $search;
$info = $this->_objZip->statName($name);
// l'image n'est pas trouvé
if ($info === FALSE) {
return "RI : L'image n'est pas présente dans le docx. (" . $name . ")";
}
// image est trouvé, il reste à la remplacer
$ret = $this->_objZip->deleteName($name);
if (!$ret) {
return 'RI pb delete image';
}
$ret = $this->_objZip->addFile($urlImage, $name);
if (!$ret) {
return 'RI addFile';
}
return TRUE;
}
示例3: pleiofile_add_folder_to_zip
function pleiofile_add_folder_to_zip(ZipArchive &$zip_archive, ElggObject $folder, $folder_path = "")
{
if (!empty($zip_archive) && !empty($folder) && elgg_instanceof($folder, "object", "folder")) {
$folder_title = elgg_get_friendly_title($folder->title);
$zip_archive->addEmptyDir($folder_path . $folder_title);
$folder_path .= $folder_title . DIRECTORY_SEPARATOR;
$file_options = array("type" => "object", "subtype" => "file", "limit" => false, "relationship" => "folder_of", "relationship_guid" => $folder->getGUID());
// add files from this folder to the zip
if ($files = elgg_get_entities_from_relationship($file_options)) {
foreach ($files as $file) {
// check if the file exists
if ($zip_archive->statName($folder_path . $file->originalfilename) === false) {
// doesn't exist, so add
$zip_archive->addFile($file->getFilenameOnFilestore(), $folder_path . sanitize_file_name($file->originalfilename));
} else {
// file name exists, so create a new one
$ext_pos = strrpos($file->originalfilename, ".");
$file_name = substr($file->originalfilename, 0, $ext_pos) . "_" . $file->getGUID() . substr($file->originalfilename, $ext_pos);
$zip_archive->addFile($file->getFilenameOnFilestore(), $folder_path . sanitize_file_name($file_name));
}
}
}
// check if there are subfolders
$folder_options = array("type" => "object", "subtype" => "folder", "limit" => false, "metadata_name_value_pairs" => array("parent_guid" => $folder->getGUID()));
if ($sub_folders = elgg_get_entities_from_metadata($folder_options)) {
foreach ($sub_folders as $sub_folder) {
pleiofile_add_folder_to_zip($zip_archive, $sub_folder, $folder_path);
}
}
}
}
示例4: zipfile_crc32
function zipfile_crc32($filename)
{
$zip = new ZipArchive();
$res = $zip->open($filename);
$filename = basename($filename, ".zip");
$stats = $zip->statName($filename, ZipArchive::FL_NOCASE | ZipArchive::FL_NODIR);
$result = dechex($stats["crc"]);
$zip->close();
return $result;
}
示例5: assertFileExists
public static function assertFileExists($fileZip, $path)
{
$oZip = new \ZipArchive();
if ($oZip->open($fileZip) !== true) {
return false;
}
if ($oZip->statName($path) === false) {
return false;
}
return true;
}
示例6: canRead
/**
* Can the current PHPExcel_Reader_IReader read the file?
*
* @param string $pFilename
* @return boolean
* @throws PHPExcel_Reader_Exception
*/
public function canRead($pFilename)
{
// Check if file exists
if (!file_exists($pFilename)) {
throw new PHPExcel_Reader_Exception("Could not open " . $pFilename . " for reading! File does not exist.");
}
// Check if zip class exists
if (!class_exists('ZipArchive', FALSE)) {
throw new PHPExcel_Reader_Exception("ZipArchive library is not enabled");
}
$mimeType = 'UNKNOWN';
// Load file
$zip = new ZipArchive();
if ($zip->open($pFilename) === true) {
// check if it is an OOXML archive
$stat = $zip->statName('mimetype');
if ($stat && $stat['size'] <= 255) {
$mimeType = $zip->getFromName($stat['name']);
} elseif ($stat = $zip->statName('META-INF/manifest.xml')) {
$xml = simplexml_load_string($zip->getFromName('META-INF/manifest.xml'));
$namespacesContent = $xml->getNamespaces(true);
if (isset($namespacesContent['manifest'])) {
$manifest = $xml->children($namespacesContent['manifest']);
foreach ($manifest as $manifestDataSet) {
$manifestAttributes = $manifestDataSet->attributes($namespacesContent['manifest']);
if ($manifestAttributes->{'full-path'} == '/') {
$mimeType = (string) $manifestAttributes->{'media-type'};
break;
}
}
}
}
$zip->close();
return $mimeType === 'application/vnd.oasis.opendocument.spreadsheet';
}
return FALSE;
}
示例7: serveFileFromZIP
function serveFileFromZIP($baseDir, $zipName, $fileName)
{
$zip = new ZipArchive();
if ($zip->open($baseDir . $zipName) !== TRUE) {
handleError("Could not open ZIP file '{$zipName}'");
}
$contents = $zip->getStream($fileName);
if ($contents === FALSE) {
$zip->close();
handleError("Could not find file '{$fileName}' in ZIP file '{$zipName}'");
}
$fileSize = $zip->statName($fileName)['size'];
header('Content-Length: ' . $fileSize);
header('Content-Type: text/plain');
fpassthru($contents);
fclose($contents);
$zip->close();
exit;
}
示例8: __construct
/**
* @param string $file_name
*/
public function __construct($file_name)
{
parent::__construct($file_name);
$archive = strstr($file_name, '#', true);
if (strpos($archive, 'zip://') === 0) {
$this->_zip_name = substr($archive, strlen('zip://'));
} else {
$this->_zip_name = $archive;
}
$filename = substr(strstr($file_name, '#'), 1);
$zip = new \ZipArchive();
$ret = $zip->open($this->_zip_name);
if (true !== $ret) {
$message = sprintf('zip error', $ret);
throw new \RuntimeException($message);
}
$this->_stat = $zip->statName($filename);
$this->_zip = $zip;
$this->_file_name = $filename;
}
示例9: inspect_zip
public function inspect_zip(ZipArchive $zip)
{
$content = array('db' => false, 'fs' => false, 'auto-install' => false);
if (count(array_filter(array('index.php', 'wp-config.php'), array($zip, 'statName'))) > 0) {
$content['fs'] = true;
}
if ($zip->statName('database.txt') !== false) {
$content['db'] = true;
}
if ($content['db'] || $content['fs']) {
return $content;
}
$s = '/auto-install/database.txt';
for ($index = 0; $index < $zip->numFiles; ++$index) {
$name = $zip->getNameIndex($index);
if (substr($name, -strlen($s)) === $s) {
$content['auto-install'] = true;
break;
}
}
return $content;
}
示例10: getFromStream
protected function getFromStream()
{
try {
$za = new ZipArchive();
if ($za->open($this->mwb)) {
if (0 < $za->numFiles) {
$stat = $za->statIndex(0);
$filename = $stat["name"];
if (basename($filename) == "document.mwb.xml") {
$fp = $za->getStream($filename);
if (!$fp) {
throw new Exception("Error: can't get stream to zipped file");
} else {
$stat = $za->statName($stat["name"]);
$buf = "";
ob_start();
while (!feof($fp)) {
$buf .= fread($fp, 2048);
}
$xmlstream = ob_get_contents();
ob_end_clean();
if (stripos($xmlstream, "CRC error") != FALSE) {
$errBuff = '';
ob_start();
echo 'CRC32 mismatch, current ';
printf("%08X", crc32($buf));
//current CRC
echo ', expected ';
printf("%08X", $stat['crc']);
//expected CRC
$error = ob_get_contents();
ob_end_clean();
fclose($fp);
throw new Exception($error);
}
fclose($fp);
$this->xmlstream = $buf;
}
} else {
throw new Exception("archive has to contain document.mwb.xml as first entry document.");
}
} else {
$za->close();
throw new Exception("zip archive is empty");
}
} else {
throw new Exception("could not open archive " . $this->mwb);
}
} catch (Exception $e) {
$this->error = $e->getMessage();
}
}
示例11: addRunnerToArchive
private function addRunnerToArchive($archive, $worker_file_name, $options = array())
{
$zip = new \ZipArchive();
if (!$zip->open($archive, \ZIPARCHIVE::CREATE) === true) {
$zip->close();
throw new IronWorkerException("Archive {$archive} was not found!");
}
if ($zip->statName($worker_file_name) === false) {
$zip->close();
throw new IronWorkerException("File {$worker_file_name} in archive {$archive} was not found!");
}
if (!empty($options['set_env']) && is_array($options['set_env'])) {
$envs = $options['set_env'];
} else {
$envs = array();
}
if (!$zip->addFromString('runner.php', $this->workerHeader($worker_file_name, $envs))) {
throw new IronWorkerException("Adding Runner to the worker failed");
}
$zip->close();
return true;
}
示例12: addRunnerToArchive
private function addRunnerToArchive($archive, $worker_file_name)
{
$zip = new ZipArchive();
if (!$zip->open($archive, ZIPARCHIVE::CREATE) === true) {
$zip->close();
throw new IronWorker_Exception("Archive {$archive} was not found!");
}
if ($zip->statName($worker_file_name) === false) {
$zip->close();
throw new IronWorker_Exception("File {$worker_file_name} in archive {$archive} was not found!");
}
if (!$zip->addFromString('runner.php', $this->workerHeader($worker_file_name))) {
throw new IronWorker_Exception("Adding Runner to the worker failed");
}
$zip->close();
return true;
}
示例13: zip_contents
/**
* @author Jack
* @date Sun Sep 20 21:57:13 2015
* @version 1.1
*/
function zip_contents($file, $path)
{
$file = safe_add_extension($file, 'zip');
if (file_exists($file)) {
if (filesize($file) >= 4294967296) {
// If the file is bigger than 4G, we can't use PHP's zip for now
$p7zip = config('p7zip', '/opt/local/bin/7z');
if (!file_exists($p7zip)) {
$p7zip = '/usr/bin/7za';
}
$spec = array(array("pipe", "r"), array("pipe", "w"), array("pipe", "w"));
$p = proc_open("{$p7zip} x -so {$file} '{$path}'", $spec, $pipes);
if (is_resource($p)) {
$data = stream_get_contents($pipes[1]);
fclose($pipes[1]);
proc_close($p);
return $data;
}
} else {
$zip = new \ZipArchive();
if ($zip->open($file)) {
if ($zip->statName($path)) {
return file_get_contents('zip://' . $file . '#' . $path);
}
}
}
}
return null;
}
示例14: zipCheck
public function zipCheck($extendtype, $pluginurl, $pluginfile, $pluginfilename)
{
//Save extend zip file to server
$data = file_get_contents($pluginurl);
$fp = fopen($pluginfile, "wb");
fwrite($fp, $data);
fclose($fp);
if ($extendtype == "languages" || $extendtype == "themes") {
return true;
} elseif ($extendtype == "plugins") {
$zip = new ZipArchive();
if ($zip->open(GSADMINPATH . $pluginfile) === TRUE) {
if ($zip->statName($pluginfilename) != "") {
return true;
} else {
return false;
}
$zip->close();
}
}
}
示例15: file_tools_add_folder_to_zip
/**
* Add a folder to a zip file
*
* @param ZipArchive &$zip_archive the zip file to add files/folder to
* @param ElggObject $folder the folder to add
* @param string $folder_path the path of the current folder
*
* @return void
*/
function file_tools_add_folder_to_zip(ZipArchive &$zip_archive, ElggObject $folder, $folder_path = '')
{
if (!$zip_archive instanceof ZipArchive || !elgg_instanceof($folder, 'object', FILE_TOOLS_SUBTYPE)) {
return;
}
$folder_title = elgg_get_friendly_title($folder->title);
$zip_archive->addEmptyDir($folder_path . $folder_title);
$folder_path .= $folder_title . DIRECTORY_SEPARATOR;
$file_options = ['type' => 'object', 'subtype' => 'file', 'limit' => false, 'relationship' => FILE_TOOLS_RELATIONSHIP, 'relationship_guid' => $folder->getGUID()];
// add files from this folder to the zip
$files = new ElggBatch('elgg_get_entities_from_relationship', $file_options);
foreach ($files as $file) {
// check if the file exists
if ($zip_archive->statName($folder_path . $file->originalfilename) === false) {
// doesn't exist, so add
$zip_archive->addFile($file->getFilenameOnFilestore(), $folder_path . $file->originalfilename);
} else {
// file name exists, so create a new one
$ext_pos = strrpos($file->originalfilename, '.');
$file_name = substr($file->originalfilename, 0, $ext_pos) . '_' . $file->getGUID() . substr($file->originalfilename, $ext_pos);
$zip_archive->addFile($file->getFilenameOnFilestore(), $folder_path . $file_name);
}
}
// check if there are subfolders
$folder_options = ['type' => 'object', 'subtype' => FILE_TOOLS_SUBTYPE, 'limit' => false, 'metadata_name_value_pairs' => ['parent_guid' => $folder->getGUID()]];
$sub_folders = new ElggBatch('elgg_get_entities_from_metadata', $folder_options);
foreach ($sub_folders as $sub_folder) {
file_tools_add_folder_to_zip($zip_archive, $sub_folder, $folder_path);
}
}