简体   繁体   中英

Extract part of zip file with PHP

For a project, I would like to read a specific file in an uploaded archive (zip file). The file always has the same name/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';
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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