假设我有一个名为并实例化的变量:
$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
任何帮助都会很棒。