-1

我有这个用于在 php 中下载图像的代码......工作正常,图像下载但问题是它没有在下载的地方打开,并给出错误“无法读取文件头......未知文件格式! ”

<?php
$path = $row['img_url'].".jpg";
echo $path;
$filename = $path;
$ctype="application/.jpg";
// required for IE, otherwise Content-disposition is ignored
if(ini_get('zlib.output_compression'))
ini_set('zlib.output_compression', 'Off');
header("Pragma: public"); // required
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false); // required for certain browsers
header("Content-Type: $ctype");
// change, added quotes to allow spaces in filenames
header("Content-Disposition: attachment; filename=\"".basename($filename)."\";" );
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($filename));
readfile("$filename");
exit();
?>
4

4 回答 4

3

更改内容类型

$ctype="application/.jpg"; //It's a invalid content type

$ctype="image/jpeg";
于 2012-12-14T05:57:50.263 回答
2

尝试使用image/jpegMIME 类型而不是application/.jpg

于 2012-12-14T05:58:15.307 回答
2

您不应该在标题之前回显任何内容并尝试使用 header('Content-Type: image/jpeg');

于 2012-12-14T06:00:18.603 回答
1

您的内容类型错误。尝试使用$ctype="image/jpeg";

于 2012-12-14T05:58:08.553 回答