0
我使用下面的代碼壓縮在線圖像並將zip文件下載到本地。但是顯示「file not exist
」。來自URL的PHP zip圖像並下載到本地
$url = "http://www.google.com/intl/en_ALL/images/logo.gif";
$zip = new ZipArchive;
$zipname = sys_get_temp_dir() . "/" . time() . ".zip";
if ($zip->open($zipname, ZipArchive::CREATE) === TRUE) {
$zip->addFromString('logo.gif', file_get_contents($url));
$zip->close();
if (file_exists($zipname)) {
// force to download the zip
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private", false);
header('Content-type: application/zip');
header('Content-Disposition: attachment; filename="' . $zipname . '"');
readfile($zipname);
// remove zip file from temp path
unlink($zipname);
echo "ok";
} else {
echo "file not exist";
}
} else {
echo "failed";
}
我該如何解決?謝謝
我曾嘗試添加sys_get_temp_dir(),但仍然是 「文件不存在」。與「vfs://root/temp/1456553223.zip」相同的zipname –
我實際上不知道什麼是'vfs://',但是您是否已經手動更改了zip文件? – Armen
「vfs:// root/temp /」是sys_get_temp_dir()的路徑值。我使用控制檯日誌來查看$ zipname的值,所以我得到「vfs://root/temp/1456553223.zip」 –