从ZIP读取文件而不解压缩到磁盘

时间:2016-10-20 17:23:57

标签: php zip

是否可以在服务器上打开ZIP文件,从其内容中读取文件并将其显示/直接发送到客户端而不先将其提取到磁盘?我在谈论pdf'simages。没有在php网站上找到任何提示。

1 个答案:

答案 0 :(得分:1)

Well,there is a PHP Extension. If you use the extractTo method, you would be able to extract a single file, checkout the documentation.

From the documentation, extracting two files:-

<?php
$zip = new ZipArchive;
$res = $zip->open('test_im.zip');
if ($res === TRUE) {
    $zip->extractTo('/my/destination/dir/', array('pear_item.gif', 'testfromfile.php'));
    $zip->close();
    echo 'ok';
} else {
    echo 'failed';
}
?>

You would need to provide an array of path inside the zip.