douleijiang8111 2009-10-09 13:36
浏览 68

图像文件下载问题

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);
    }

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.

Thanks in advance. Kindly help.

  • 写回答

3条回答 默认 最新

  • draxq02664 2009-10-09 13:57
    关注

    This line: header("Content-type: application/octet-stream"); seems fishy to me. You might want to try giving the actual mime type and see if that helps

    评论

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度