本文整理汇总了PHP中zip_entry_read函数的典型用法代码示例。如果您正苦于以下问题:PHP zip_entry_read函数的具体用法?PHP zip_entry_read怎么用?PHP zip_entry_read使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了zip_entry_read函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: read_file_docx
public function read_file_docx($filename)
{
$striped_content = '';
$content = '';
if (!$filename || !file_exists($filename)) {
return false;
}
$zip = zip_open($filename);
if (!$zip || is_numeric($zip)) {
return false;
}
while ($zip_entry = zip_read($zip)) {
if (zip_entry_open($zip, $zip_entry) == FALSE) {
continue;
}
if (zip_entry_name($zip_entry) != "word/document.xml") {
continue;
}
$content .= zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
zip_entry_close($zip_entry);
}
// end while
zip_close($zip);
//echo $content;
//echo "<hr>";
//file_put_contents('1.xml', $content);
$content = str_replace('</w:r></w:p></w:tc><w:tc>', " ", $content);
$content = str_replace('</w:r></w:p>', "\r\n", $content);
$striped_content = strip_tags($content);
return $striped_content;
}
示例2: odt_unzip
public function odt_unzip($file, $save = false)
{
if (!function_exists('zip_open')) {
die('NO ZIP FUNCTIONS DETECTED. Do you have the PECL ZIP extensions loaded?');
}
if ($zip = zip_open($file)) {
while ($zip_entry = zip_read($zip)) {
$filename = zip_entry_name($zip_entry);
if (zip_entry_name($zip_entry) == 'content.xml' and zip_entry_open($zip, $zip_entry, "r")) {
$content = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
zip_entry_close($zip_entry);
}
if (preg_match('Pictures/', $filename) and !preg_match('Object', $filename) and zip_entry_open($zip, $zip_entry, "r")) {
$img[$filename] = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
zip_entry_close($zip_entry);
}
}
if (isset($content)) {
if ($save == false) {
return array($content, $img);
} else {
file_put_contents('content.xml', $content);
if (is_array($img)) {
if (!is_dir('Pictures')) {
mkdir('Pictures');
}
foreach ($img as $key => $val) {
file_put_contents($key, $val);
}
}
}
}
}
}
示例3: unzip
function unzip($file, $dir = 'unzip/')
{
if (!file_exists($dir)) {
mkdir($dir, 0777);
}
$zip_handle = zip_open($file);
if (is_resource($zip_handle)) {
while ($zip_entry = zip_read($zip_handle)) {
if ($zip_entry) {
$zip_name = zip_entry_name($zip_entry);
$zip_size = zip_entry_filesize($zip_entry);
if ($zip_size == 0 && $zip_name[strlen($zip_name) - 1] == '/') {
mkdir($dir . $zip_name, 0775);
} else {
@zip_entry_open($zip_handle, $zip_entry, 'r');
$fp = @fopen($dir . $zip_name, 'wb+');
@fwrite($fp, zip_entry_read($zip_entry, $zip_size), $zip_size);
@fclose($fp);
@chmod($dir . $zip_name, 0775);
@zip_entry_close($zip_entry);
}
}
}
return true;
} else {
zip_close($zip_handle);
return false;
}
}
示例4: unzip
function unzip($zipfile)
{
$zip = zip_open($zipfile);
while ($zip_entry = zip_read($zip)) {
zip_entry_open($zip, $zip_entry);
if (substr(zip_entry_name($zip_entry), -1) == '/') {
$zdir = substr(zip_entry_name($zip_entry), 0, -1);
if (file_exists($zdir)) {
trigger_error('Directory "<b>' . $zdir . '</b>" exists', E_USER_ERROR);
return false;
}
mkdir($zdir);
} else {
$name = zip_entry_name($zip_entry);
if (file_exists($name)) {
trigger_error('File "<b>' . $name . '</b>" exists', E_USER_ERROR);
return false;
}
$fopen = fopen($name, "w");
fwrite($fopen, zip_entry_read($zip_entry, zip_entry_filesize($zip_entry)), zip_entry_filesize($zip_entry));
}
zip_entry_close($zip_entry);
}
zip_close($zip);
return true;
}
示例5: caching
function caching($comics_id, $zip_path, $image_ext)
{
$comic = zip_open($zip_path);
if (!is_resource($comic)) {
die("[ERR]ZIP_OPEN : " . $zip_path);
}
$inzip_path = "";
$count = 0;
$files = null;
$db = new SQLite3(DB);
$db->exec("BEGIN DEFERRED;");
while (($entry = zip_read($comic)) !== false) {
$inzip_path = zip_entry_name($entry);
$cache_name = md5($zip_path . "/" . $inzip_path) . '.' . get_ext($inzip_path);
// 画像か否か
if (!is_image($inzip_path, $image_ext)) {
continue;
}
$data = zip_entry_read($entry, zip_entry_filesize($entry));
$filepath = CACHE . '/' . $cache_name;
file_put_contents($filepath, $data);
$count++;
query("INSERT INTO images (comics_id, page, filepath) VALUES (" . $comics_id . ", " . $count . ", '" . $filepath . "')", $db);
}
zip_close($comic);
query("UPDATE comics SET pages = " . $count . " WHERE id = " . $comics_id, $db);
$db->exec("COMMIT;");
}
示例6: parse
public static function parse($filename)
{
$striped_content = '';
$content = '';
if (!$filename || !file_exists($filename)) {
return false;
}
$zip = zip_open($filename);
if (!$zip || is_numeric($zip)) {
return false;
}
while ($zip_entry = zip_read($zip)) {
if (zip_entry_open($zip, $zip_entry) == FALSE) {
continue;
}
if (zip_entry_name($zip_entry) != "content.xml") {
continue;
}
$content .= zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
zip_entry_close($zip_entry);
}
zip_close($zip);
$content = str_replace('</w:r></w:p></w:tc><w:tc>', " ", $content);
$content = str_replace('</w:r></w:p>', "\r\n", $content);
$striped_content = strip_tags($content);
return $striped_content;
}
示例7: importAction
/**
* This action handles import action.
*
* It must be reached by a POST request.
*
* Parameter is:
* - file (default: nothing!)
* Available file types are: zip, json or xml.
*/
public function importAction()
{
if (!Minz_Request::isPost()) {
Minz_Request::forward(array('c' => 'importExport', 'a' => 'index'), true);
}
$file = $_FILES['file'];
$status_file = $file['error'];
if ($status_file !== 0) {
Minz_Log::error('File cannot be uploaded. Error code: ' . $status_file);
Minz_Request::bad(_t('feedback.import_export.file_cannot_be_uploaded'), array('c' => 'importExport', 'a' => 'index'));
}
@set_time_limit(300);
$type_file = $this->guessFileType($file['name']);
$list_files = array('opml' => array(), 'json_starred' => array(), 'json_feed' => array());
// We try to list all files according to their type
$list = array();
if ($type_file === 'zip' && extension_loaded('zip')) {
$zip = zip_open($file['tmp_name']);
if (!is_resource($zip)) {
// zip_open cannot open file: something is wrong
Minz_Log::error('Zip archive cannot be imported. Error code: ' . $zip);
Minz_Request::bad(_t('feedback.import_export.zip_error'), array('c' => 'importExport', 'a' => 'index'));
}
while (($zipfile = zip_read($zip)) !== false) {
if (!is_resource($zipfile)) {
// zip_entry() can also return an error code!
Minz_Log::error('Zip file cannot be imported. Error code: ' . $zipfile);
} else {
$type_zipfile = $this->guessFileType(zip_entry_name($zipfile));
if ($type_file !== 'unknown') {
$list_files[$type_zipfile][] = zip_entry_read($zipfile, zip_entry_filesize($zipfile));
}
}
}
zip_close($zip);
} elseif ($type_file === 'zip') {
// Zip extension is not loaded
Minz_Request::bad(_t('feedback.import_export.no_zip_extension'), array('c' => 'importExport', 'a' => 'index'));
} elseif ($type_file !== 'unknown') {
$list_files[$type_file][] = file_get_contents($file['tmp_name']);
}
// Import file contents.
// OPML first(so categories and feeds are imported)
// Starred articles then so the "favourite" status is already set
// And finally all other files.
$error = false;
foreach ($list_files['opml'] as $opml_file) {
$error = $this->importOpml($opml_file);
}
foreach ($list_files['json_starred'] as $article_file) {
$error = $this->importJson($article_file, true);
}
foreach ($list_files['json_feed'] as $article_file) {
$error = $this->importJson($article_file);
}
// And finally, we get import status and redirect to the home page
Minz_Session::_param('actualize_feeds', true);
$content_notif = $error === true ? _t('feedback.import_export.feeds_imported_with_errors') : _t('feedback.import_export.feeds_imported');
Minz_Request::good($content_notif);
}
示例8: read_docx
private function read_docx()
{
$striped_content = '';
$content = '';
$zip = zip_open($this->filename);
if (!$zip || is_numeric($zip)) {
return false;
}
while ($zip_entry = zip_read($zip)) {
if (zip_entry_open($zip, $zip_entry) == FALSE) {
continue;
}
if (zip_entry_name($zip_entry) != "word/document.xml") {
continue;
}
$content .= zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
zip_entry_close($zip_entry);
}
// end while
zip_close($zip);
$content = str_replace('</w:r></w:p></w:tc><w:tc>', " ", $content);
$content = str_replace('</w:r></w:p>', "\r\n", $content);
$striped_content = strip_tags($content);
return $striped_content;
}
示例9: getLayoutData
function getLayoutData($layout, $fileName, $usage, $install = false)
{
$output = "";
$zip = zip_open(($install == false ? 'layouts/' : '../layouts/') . $layout . '.zip');
if ($zip) {
while ($zip_entry = zip_read($zip)) {
$file = basename(zip_entry_name($zip_entry));
if (zip_entry_open($zip, $zip_entry, 'r')) {
if ($usage == "include" && strpos($file, $fileName) !== FALSE) {
$output = 'phar://layouts/' . $layout . '.zip/' . zip_entry_name($zip_entry);
}
if ($usage == "echo") {
$buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
if (strpos(strval($file), strval($fileName)) !== FALSE) {
if (strpos($file, 'settings') !== FALSE) {
$output = json_decode($buf, true);
} else {
$output = $buf;
}
}
}
}
}
zip_close($zip);
}
return $output;
}
示例10: unpackZip
function unpackZip($file, $dir)
{
if ($zip = zip_open(getcwd() . $file)) {
if ($zip) {
while ($zip_entry = zip_read($zip)) {
if (zip_entry_open($zip, $zip_entry, "r")) {
$buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
$dir_name = dirname(zip_entry_name($zip_entry));
if ($dir_name == "." || !is_dir($dir_name)) {
$dir_op = $dir;
foreach (explode("/", $dir_name) as $k) {
$dir_op = $dir_op . $k;
if (is_file($dir_op)) {
unlink($dir_op);
}
if (!is_dir($dir_op)) {
mkdir($dir_op);
}
$dir_op = $dir_op . "/";
}
}
$fp = fopen($dir . zip_entry_name($zip_entry), "w");
fwrite($fp, $buf);
zip_entry_close($zip_entry);
} else {
return false;
}
}
zip_close($zip);
}
} else {
return false;
}
return true;
}
示例11: unzip
public static function unzip($file, $dir)
{
$zip = new ZipArchive();
$zip->open($file);
$zip->extractTo($dir);
return;
$zip = zip_open($file);
if (!is_resource($zip)) {
return $zip;
}
while ($zipEntry = zip_read($zip)) {
$name = zip_entry_name($zipEntry);
$size = zip_entry_filesize($zipEntry);
$data = zip_entry_read($zipEntry, $size);
if (substr($name, -1, 1) == "/") {
if (!is_dir($dir . "/" . $name)) {
mkdir($dir . "/" . $name);
}
} else {
$filename = $dir . "/" . $name;
if (!is_file($filename) || md5(file_get_contents($filename)) != md5($data)) {
file_put_contents($filename, $data);
}
}
}
return true;
}
示例12: unpackInto
function unpackInto($file_path, $dir_path)
{
$zip = zip_open($file_path);
if (!is_dir($dir_path)) {
throw new Exception($dir_path . ' should be a directory but isn\'t.');
}
if ($zip) {
while ($zip_entry = zip_read($zip)) {
zip_entry_open($zip, $zip_entry);
if (substr(zip_entry_name($zip_entry), -1) == '/') {
//this $zip_entry is a directory. create it.
$zdir = substr(zip_entry_name($zip_entry), 0, -1);
mkdir($dir_path . '/' . $zdir);
} else {
$file = basename(zip_entry_name($zip_entry));
$fp = fopen($dir_path . '/' . zip_entry_name($zip_entry), "w+");
//echo zip_entry_name($zip_entry);
if (zip_entry_open($zip, $zip_entry, "r")) {
$buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
zip_entry_close($zip_entry);
}
fwrite($fp, $buf);
fclose($fp);
}
}
zip_close($zip);
}
}
示例13: unpack
static function unpack($archive, $out_folder, $file_name = '')
{
$zip = zip_open($archive);
while ($zip_entry = zip_read($zip)) {
$zip_entry_name = zip_entry_name($zip_entry);
if ($zip_entry_name != '.DS_Store') {
$zip_entry_size = zip_entry_filesize($zip_entry);
if ($zip_entry_size == 0) {
if (!file_exists($out_folder . $zip_entry_name) && !@mkdir($out_folder . $zip_entry_name)) {
throw new Exception('Can not create folder <strong>' . $out_folder . $zip_entry_name . '</strong>. Permissions denied.');
}
} else {
if (!$file_name || $out_folder . $zip_entry_name == $file_name) {
if (!@file_put_contents($out_folder . $zip_entry_name, zip_entry_read($zip_entry, $zip_entry_size))) {
throw new Exception('Can not unpack file <strong>' . $out_folder . $zip_entry_name . '</strong>. Permissions denied.');
}
if ($file_name) {
break;
}
}
}
}
}
zip_close($zip);
}
示例14: unzip
function unzip($file)
{
$zip = zip_open($file);
if (is_resource($zip)) {
$tree = "";
while (($zip_entry = zip_read($zip)) !== false) {
echo "Unpacking " . zip_entry_name($zip_entry) . "\n";
if (strpos(zip_entry_name($zip_entry), DIRECTORY_SEPARATOR) !== false) {
$last = strrpos(zip_entry_name($zip_entry), DIRECTORY_SEPARATOR);
$dir = substr(zip_entry_name($zip_entry), 0, $last);
$file = substr(zip_entry_name($zip_entry), strrpos(zip_entry_name($zip_entry), DIRECTORY_SEPARATOR) + 1);
if (!is_dir($dir)) {
@mkdir($dir, 0755, true) or die("Unable to create {$dir}\n");
}
if (strlen(trim($file)) > 0) {
$return = @file_put_contents($dir . "/" . $file, zip_entry_read($zip_entry, zip_entry_filesize($zip_entry)));
if ($return === false) {
die("Unable to write file {$dir}/{$file}\n");
}
}
} else {
file_put_contents($file, zip_entry_read($zip_entry, zip_entry_filesize($zip_entry)));
}
}
} else {
echo "Unable to open zip file\n";
}
}
示例15: version_get
/**
* APP版本更新接口
* @date: 2016年1月10日 下午9:30:33
*
* @author : Elliot
* @param
* : none
* @return :
*/
public function version_get()
{
$dir = 'data';
$dh = @opendir($dir);
$return = array();
while ($file = @readdir($dh)) {
// 循环读取目录下的文件
if ($file != '.' and $file != '..') {
$path = $dir . DIRECTORY_SEPARATOR . $file;
// 设置目录,用于含有子目录的情况
if (is_file($path)) {
$filetime[] = date("Y-m-d H:i:s", filemtime($path));
// 获取文件最近修改日期
$return[] = $dir . DIRECTORY_SEPARATOR . $file;
}
}
}
@closedir($dh);
// 关闭目录流
array_multisort($filetime, SORT_DESC, SORT_STRING, $return);
// 按时间排序
$file = current($return);
$zip = zip_open($file);
if ($zip) {
while ($zip_entry = zip_read($zip)) {
if (zip_entry_name($zip_entry) == self::INSTALLPACKETVERSIONFILE && zip_entry_open($zip, $zip_entry, "r")) {
$buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
zip_entry_close($zip_entry);
}
}
zip_close($zip);
}
$result = array('version' => $buf, 'url' => 'http://' . $_SERVER['SERVER_NAME'] . DIRECTORY_SEPARATOR . $file);
$this->response($result, 200);
}