$image_name = rawurldecode($name);
$image_path = 'http://' . rawurldecode($path) . '/resources/images/banner/' . $image_name;
$mime = explode('.', $image_name);
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header('Content-Type: image/' . $mime[1]);
header("Content-Disposition: attachment; filename=$image_name");
header('Content-Transfer-Encoding: binary');
ob_clean();
flush();
readfile($image_path);
我上面有这个代码在我的本地运行正常但是当我在我的服务器上传它时我仍然可以下载但是图像坏了。你可以看到图像的上半部分,但下半部分都是灰色的。
答案 0 :(得分:0)
你能试试吗?
$image_name = rawurldecode($name);
$image_path = 'http://' . rawurldecode($path) . '/resources/images/banner/' . $image_name;
$mime = explode('.', $image_name);
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($image_path));
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($image_path));
readfile($image_name);
exit;