如何读取zip存档中的单个文件 [英] How to read a single file inside a zip archive

查看:73
本文介绍了如何读取zip存档中的单个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在zip文件中读取单个文件"test.txt"的内容.整个zip文件是一个非常大的文件(2gb),其中包含很多文件(10,000,000),因此,提取整个文件对我而言不是一个可行的解决方案.如何读取单个文件?

I need to read the content of a single file, "test.txt", inside of a zip file. The whole zip file is a very large file (2gb) and contains a lot of files (10,000,000), and as such extracting the whole thing is not a viable solution for me. How can I read a single file?

推荐答案

尝试使用 zip://包装器:

Try using the zip:// wrapper:

$handle = fopen('zip://test.zip#test.txt', 'r'); 
$result = '';
while (!feof($handle)) {
  $result .= fread($handle, 8192);
}
fclose($handle);
echo $result;

您也可以使用 file_get_contents :

You can use file_get_contents too:

$result = file_get_contents('zip://test.zip#test.txt'); 
echo $result;

这篇关于如何读取zip存档中的单个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆