Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 图像文件下载问题_Php_Image_Download - Fatal编程技术网

Php 图像文件下载问题

Php 图像文件下载问题,php,image,download,Php,Image,Download,我在从服务器下载任何图像文件时遇到问题 我能够成功上传它们,并且可以从上传和存储它们的位置打开它们 当我使用我的功能下载时,图像文件被完全下载,文件大小也是正确的,但是当我打开它们时,我得到一个错误没有图像预览 $fileString=$fileDir.'/'.$fileName; // combine the path and file // translate file name properly for Internet Explorer. if (strstr($_SERVER[

我在从服务器下载任何图像文件时遇到问题

我能够成功上传它们,并且可以从上传和存储它们的位置打开它们

当我使用我的功能下载时,图像文件被完全下载,文件大小也是正确的,但是当我打开它们时,我得到一个错误没有图像预览

$fileString=$fileDir.'/'.$fileName; // combine the path and file
    // translate file name properly for Internet Explorer.
if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE"))
{
      $instance_name = preg_replace('/\./', '%2e', $instance_name, substr_count($instance_name, '.') - 1);
}
// make sure the file exists before sending headers

if(!$fdl=@fopen($fileString,'r'))
    {
       die("Cannot Open File!");
    } 
else 
    {
      header("Cache-Control: ");// leave blank to avoid IE errors
      header("Pragma: ");// leave blank to avoid IE errors
      header("Content-type: application/octet-stream");
      header("Content-Disposition: attachment; filename=\"".$instance_name."\"");
      header("Content-length:".(string)(filesize($fileString)));
      sleep(1);
      fpassthru($fdl);
    }
我使用IE作为浏览器

我使用此代码段下载文件,而不是在浏览器上显示。脚本执行后,系统会提示我是否要打开/保存该文件。当我保存文件的大小也是正确的,但图像没有显示。当我右键单击并查看文件摘要时,它表示该摘要不可用


提前谢谢。请帮忙。

这一行:
标题(“内容类型:应用程序/八位字节流”)对我来说似乎可疑。您可能想尝试给出实际的mime类型,看看这是否有帮助。

代码中不清楚,您是否使用此PHP代码段在网页上提供图像,例如:

<img src="my-php-script.php" alt="blah blah blah" />


如果是,则说明您的内容类型不正确。您需要使用图像MIME类型,如image/gif、image/jpeg、image/png或image/tiff,以最合适的为准。

问题在于MIME类型。请看这里:

如果要在浏览器中查看图像,则需要执行此操作

如果您想将它们作为二进制文件下载,请保留mime类型

另外,请将文件打开模式从“r”更改为“rb”

尝试从“@fopen”中删除@,如果有错误,请查看错误