Domanda

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

È stato utile?

Soluzione

$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';
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top