我使用以下代码压缩在线图像并将压缩文件下载到本地。但显示“ file not exist
”。
$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";
}
我该如何解决?谢谢