0
可以說我有一個名爲和實例變量:從字符串到新的文件夾添加文件ZipArchive
$css = 'body {color:red;}';
目前,我建立我的zip文件如下:
ini_set("max_execution_time", 300);
// create object
$zip = new ZipArchive();
// open archive
if ($zip->open("my-archive.zip", ZIPARCHIVE::CREATE) !== TRUE) {
die ("Could not open archive");
}
// initialize an iterator
// pass it the directory to be processed
$jsFiles = new RecursiveIteratorIterator(new RecursiveDirectoryIterator("../js"));
$cssFiles = new RecursiveIteratorIterator(new RecursiveDirectoryIterator("../css"));
$images = new RecursiveIteratorIterator(new RecursiveDirectoryIterator("../_design"));
// iterate over the directory
// add each file found to the archive
foreach ($jsFiles as $key=>$value) {
$zip->addFile(realpath($key), $key) or die ("ERROR: Could not add file: $key");
}
foreach ($cssFiles as $key=>$value) {
$zip->addFile(realpath($key), $key) or die ("ERROR: Could not add file: $key");
}
foreach ($images as $key=>$value) {
$zip->addFile(realpath($key), $key) or die ("ERROR: Could not add file: $key");
}
// close and save archive
$zip->close();
echo "Archive created successfully.";
讓說我已經有一個名爲color.css
的文件位於/css/main/color.css/
,我希望我的新字符串$css
替換這個整個新文件在檔案,我該怎麼做?我看過ZipArchive::addFromString
,但是我看不到一種方法將它放在某個文件夾中。這是唯一需要在整個目錄中進行更改的文件。
任何幫助將是偉大的。
啊,當然,嘗試有病啊! –