我一直在這一段時間。這實際上工作了一次,然後再也沒有。它根本不會創建zip文件。該文件確實存在。使用zipArchive addFile()不會將圖像添加到zip
$zip = new ZipArchive();
$filename = "./test" . time() .".zip";
if ($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE) {
exit("cannot open <$filename>\n");
}
$thisdir = "$_SERVER[DOCUMENT_ROOT]/zip";
$zip->addFile($thisdir . "/trash-icon.png", "/gabage.png");
echo "numfiles: " . $zip->numFiles . "\n";
echo "status:" . $zip->status . "\n";
$zip->close();
如果我添加類似
$zip->addFromString("testfilephp.txt", "#1 This is a test string added as testfilephp.txt.\n");
它創建與它的txt文件的zip ..但一個沒有去爲anytype類型現有的文件。
'/ trash-icon.png'幾乎肯定是錯誤的,因爲它指向服務器的根目錄。你是否100%確定你試圖添加的文件實際上存在? – 2011-03-24 17:23:03
您確定/trash-icon.png確實存在,請記住它位於文件系統根目錄 – 2011-03-24 17:24:02
http://www.php.net/manual/de/function.ziparchive-addfile.php#101605 – mario 2011-03-24 17:25:17