Question

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

Was it helpful?

Solution

$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';
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top