简体   繁体   English

用PHP提取部分zip文件

[英]Extract part of zip file with PHP

For a project, I would like to read a specific file in an uploaded archive (zip file). 对于项目,我想读取上传档案(zip文件)中的特定文件。 The file always has the same name/relative-path. 该文件始终具有相同的名称/ relative-path。

Is it possible to only extract this file, or should I extract the entire archive? 是否可以只提取此文件,还是应该提取整个存档?

Thanks 谢谢

$files = array('/a_path/titi.txt'); //create a list of files to be extracted here

$zip = new ZipArchive;
$res = $zip->open('test_im.zip');
if ($res === TRUE) {
    $zip->extractTo('/my/destination/dir/', $files);
    $zip->close();
    echo 'ok';
} else {
    echo 'failed';
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM