0
我有一個具有多個路徑的數組,我寫了創建.zip文件的代碼。如何用動態路徑或多個路徑壓縮文件?
這裏是代碼:
<?php
$array = array("name" => "/sites/README.txt",
"test" => "/sites/chessboard.jpg"
);
foreach($array as $key => $value)
{
$test = $value ;
echo "zip started";
$zip = new ZipArchive();
$ow = 1;
$file= "/sites/master.zip";
if($zip->open($file,$ow?ZIPARCHIVE::OVERWRITE:ZIPARCHIVE::CREATE)===TRUE)
{
echo "zip entered to if class";
// Add the files to the .zip file
$zip->addFile($test);
// $zip->addFile($value);
// Closing the zip file
$zip->close();
}
}
?>
而且問題是在陣列$value
具有多個文件路徑。 此代碼取最後一個文件路徑並創建zip。
我想採取所有路徑並創建一個zip文件並將其存儲在文件夾中。