图像文件下载问题 [英] Image file download problem

查看:197
本文介绍了图像文件下载问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am facing problem in downloading any image file from the server.

我可以成功上传它们,并可以从上传的位置打开它们,存储。

I am able to upload them successfully and can open them from the location where they are uploaded and stored.

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

When i download using my function the image files get downloaded fully, file size is also correct but when i open them i get an error No image preview !!!

$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作为浏览器。

I am using IE as browser.

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

I am using this code snippet to download the file and not to show on the browser. The script executes and i get prompted on whether i want to open / save the file. When i save the file the size is also correct but the image doesn't show up. When i right click and see the summary of the file, it says the summary is unavailable.

提前感谢。请帮助。

推荐答案

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

It's not clear from your code, are you using this PHP snippet to serve the image on a web page, such as:

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

如果是,您的内容类型不正确。您需要使用图像MIME类型,例如image / gif,image / jpeg,image / png或image / tiff,以最合适的方式。

If so, your content-type is incorrect. You would need to use an image MIME type, such as image/gif, image/jpeg, image/png or image/tiff, whichever is most appropriate.

这篇关于图像文件下载问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆