[英]PHP extract from zip one file at a time
I am using $zip->extractTo()
to extract my zip file, this creates a new folder with all the files in it, I am just wondering if there is away I can extract the files one at a time and have them inside the root folder and not create a folder for me? 我正在使用
$zip->extractTo()
提取我的zip文件,这将创建一个包含所有文件的新文件夹,我只是想知道是否可以一次提取一个文件并将其放入根文件夹而不为我创建文件夹?
$zip = new ZipArchive();
if ($zip->open($path) === true) {
$zip->extractTo('../images/galleries/' . $galleryName);
$zip->close();
}
You can use the getFromName
or getFromIndex
methods to extract content from individual files, and then write to disk. 您可以使用
getFromName
或getFromIndex
方法从单个文件中提取内容,然后写入磁盘。 For example: 例如:
$zip = new ZipArchive;
$zip_filepath = '/path/to/zip/file';
$target_filepath = 'path/to/file/inside/zip';
$dest_filepath = '/path/to/extracted/file';
if ($zip->open($zip_filepath) === TRUE) {
file_put_contents( $dest_filepath , $zip->getFromName( $target_filepath ) );
$zip->close();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.