Php 从目录获取文件并将其添加到zip文件
我已经创建了一个名为“files.zip”的zip文件。我的属性图像文件夹中有图像。我已经扫描了那个目录,找到了我需要的文件类型。”$prop_image'是另一个具有图像名称的数组。如果图像文件(在变量“$file1”中)在该数组中,那么我将尝试将该文件添加到zip文件中Php 从目录获取文件并将其添加到zip文件,php,arrays,file,directory,zip,Php,Arrays,File,Directory,Zip,我已经创建了一个名为“files.zip”的zip文件。我的属性图像文件夹中有图像。我已经扫描了那个目录,找到了我需要的文件类型。”$prop_image'是另一个具有图像名称的数组。如果图像文件(在变量“$file1”中)在该数组中,那么我将尝试将该文件添加到zip文件中 $zip = new ZipArchive(); $filename = "files.zip"; if ($zip->open($filename, ZipArchi
$zip = new ZipArchive();
$filename = "files.zip";
if ($zip->open($filename, ZipArchive::CREATE)!==TRUE) {
exit("cannot open <$filename>\n");
}
$dir = './property_image';
$file1 = scandir($dir);
foreach($file1 as $feel){
$userfile_extn = substr($feel, strrpos($feel, '.')+1);
if($userfile_extn === 'jpg' || $userfile_extn === 'png' || $userfile_extn === 'gif' || $userfile_extn === 'jpeg'){
if(in_array($feel, $prop_image)){
$zip->addFile("$feel", basename($feel));
}
} // end of if($extension ===
}
$zip->addFile("$File", basename($File));
$zip->close();
我需要添加来自该目录的文件,这些文件位于zip文件中变量“$prop_image”的内部
$zip = new ZipArchive();
$filename = "files.zip";
if ($zip->open($filename, ZipArchive::CREATE)!==TRUE) {
exit("cannot open <$filename>\n");
}
$dir = './property_image';
$file1 = scandir($dir);
foreach($file1 as $feel){
$userfile_extn = substr($feel, strrpos($feel, '.')+1);
if($userfile_extn === 'jpg' || $userfile_extn === 'png' || $userfile_extn === 'gif' || $userfile_extn === 'jpeg'){
if(in_array($feel, $prop_image)){
$zip->addFile("$feel", basename($feel));
}
} // end of if($extension ===
}
$zip->addFile("$File", basename($File));
$zip->close();
我该怎么做 我解决了
这可能会对其他人有所帮助,所以,我在发布我的答案。那很容易。我只需要给出保存图像的文件夹名称
像这样:
$zip->addFile("./property_image/$feel", basename($feel));
代替::
$zip->addFile("$feel", basename($feel));