php如何读取zip内容?(zip_entry_read函数的使用)
web PHP 2019-04-25 2045 0
关于本站

“最难不过坚持”

本人承接扒站仿站,php网站维护,病毒查杀,网站编辑,网站改版,html制作

有需要网站维护,改版,病毒查杀,网站编辑,网站备案,html制作等相关的工作可以联系我。
本人有多年相关工作经验,也可提供免费咨询,交个朋友。
有需要探讨问题的朋友,也可以加我微信,共同探讨!
微信:15011482830 QQ:408917339

6282202 2594 39
最新评论
https://jueru.net/
评 留言
:weixiao:
评 留言
:shuijiao: :weiqu: :zhenbang: :leng:
评 留言
:yiwen: :yiwen: :yiwen: :yiwen:
评 EasySass: could not generate CSS file. See Output panel for details.
这个业务逻辑多少都有点奇怪了,阅读浏览次数增值在新闻详情页的控制器方法里setInc,这怎么还写进模型事件里了。如果非要用onAfterRead也可以,把新闻文章的内容单独分出来一个news_content表,然后把它和news做关联,然后给news_content表的onAfterRead事件做增值处理,这样点进新闻页内查询到文章内容时才会触发它。
评 TP6模型事件-查询后onAfterRead不好用
文章标签更多
ThinkPHP (254)
Mysql (58)
DedeCms (33)
jQuery (67)
证件照 (1)
setInc (4)
setDec (4)
onclick (5)
打开边栏(ESC) 关闭边栏(ESC)
zip_entry_read()函数是PHP中内置的函数,用于从打开的zip归档条目中读取内容。正在读取zip条目,返回的字节数可以作为参数发送给zip_entry_read()函数,如果成功,它将返回指定zip条目的内容,否则将返回PHP警告。
语法:
string zip_entry_read( $zip_entry, $length )
参数:
该函数接受两个参数,如下所述。
$zip_entry:这是一个指定zip条目资源的强制参数。
$length:它是一个可选参数,指定要返回的字节数。
返回值:
成功时返回指定zip条目的内容,否则返回PHP警告。
错误和异常:
如果zip存档无效,zip_entry_read()函数将返回ER_OPEN错误。

如果zip存档为空,则zip_entry_read()函数返回ER_NOZIP错误

示例一

假设zip文件article.zip包含文件:geeks.txt() 

<?php 
// 打开zip文件
$zip_handle = zip_open("articles.zip"); 
// 读取zip存档项
while($zip_entry = zip_read($zip_handle))  
{  
    $resource = zip_entry_open($zip_handle, $zip_entry, "rb"); 
    $file_name = zip_entry_name($zip_entry); 
    if ($resource == true)  
    {  
        // 读取zip存档项的内容
        $file_content = zip_entry_read($zip_entry); 
        echo("File: " . $file_name . " successfully opened. <br>"); 
        echo("File content: " . $file_content); 
        // 关闭zip归档项
        zip_entry_close($zip_entry); 
    }  
    else
        echo("Failed to Open."); 
} 
// 关闭zip文件
zip_close($zip_handle); 
// 输出:
// File: articles/geeks successfully opened. 
// File content: Welcome to GeeksforGeeks. It is a computer science portal
// where you can learn programming.
?>
示例二

假设zip文件article.zip包含以下文件:geeks.txt,geeks1.txt

<?php 
$zip_handle = zip_open("articles.zip"); 
while($zip_entry = zip_read($zip_handle))  
{  
    $resource = zip_entry_open($zip_handle, $zip_entry, "rb"); 
    $file_name = zip_entry_name($zip_entry); 
    if ($resource == true)  
    {  
        // 读取zip存档项的内容,最多可达150字节
        $file_content = zip_entry_read($zip_entry, 150); 
        echo("File Name: " . $file_name . " is opened Successfully. <br>"); 
        echo($file_content); 
        echo("<br><br>"); 
        zip_entry_close($zip_entry); 
    }  
    else
        echo("Failed to Open."); 
}  
zip_close($zip_handle); 
// 输出
// File Name: articles/geeks is opened Successfully. 
// Welcome to GeeksforGeeks. It is a computer science portal where you
// can learn programming.

// File Name: articles/geeks1 is opened Successfully. 
// A Computer Science portal for geeks. It contains well written, well
// thought and well-explained computer science and programming articles,
// quizzes and many more.
?>

版权声明:本篇文章来源于网络。 来源链接

相关推荐
php实现ZIP压缩文件解压缩,中文乱码解决方法(重要)
PHP | 2019-04-30 5541
直接上代码,具体代码里面都有注释。直接中文压缩文件解压到中文文件夹。 <?php // 需开启配置 php_zip.dll // phpinfo(); header("Content-type:text/html;charset=utf-8"); /* * $filename 被解压文件名 * $path 解压...
openssl_private_decrypt解密失败
PHP | 2019-01-16 5515
复制别人的解密程序,原程序可以解密,复制过来就不可以 一步步尝试发现,秘钥换行符有区别, 原秘钥有换行符,复制过来不知道什么时候把换行符清空了,成了一行字符串了。
评论:0条
评论加载中...
发表评论