简体   繁体   English

Codeigniter Force下载IE

[英]Codeigniter Force download IE

I am having trouble with the download helper in ie..basically I built a site that dynamically creates pdf invoices and pdf proofs in both cases the force download works great in firefox, chrome and opera. 我在使用下载帮助程序时遇到了麻烦,即基本上建立了一个动态创建pdf发票和pdf证明的网站,在两种情况下,强制下载在Firefox,Chrome和Opera中都非常有效。 In IE it fails everytime and I get the following error: Unable to download $filename from mysite.com 在IE中,它每次都会失败,并且出现以下错误:无法从mysite.com下载$ filename

Unable to open this Internet site. 无法打开此Internet站点。 The requested site is either unavailable or cannot be found. 请求的站点不可用或找不到。 Please try again later. 请稍后再试。

To begin the force_download I have a anchor target _blank with a url that directs to the following controller: 要开始force_download,我有一个锚定目标_blank,其URL指向以下控制器:

        function view_uploaded_file($order = 0, $name = NULL){

        $this->load->helper('directory');

        $params['where'] = array('id' => id_clean($order));

        $data['order'] = $this->MOrders->get($params);

        if($data['order']->id < 1){

            redirect('admin/orders');

        }

        $name = db_clean(urldecode($name));

        $map = directory_map('./uploads/customer_order_uploads/'.$data['order']->user_id.'/'.$data['order']->id, 1);

        if(is_array($map) && in_array($name, $map)){

            $this->load->helper('download');

            $data = file_get_contents('./uploads/customer_order_uploads/'.$data['order']->user_id.'/'.$data['order']->id.'/'.urldecode($name));

            force_download($name, $data);

        } else {

            redirect('admin/orders');

        }

    }

Originally I thought maybe a problem with MY IE but I am able to download PDFs on other sites. 本来我以为我的IE可能有问题,但是我可以在其他站点上下载PDF。 I then thought that it could be a problem with codeigniters download helper but I see they already made special provisions for IE in the helper. 然后,我认为Codeigniter下载帮助程序可能存在问题,但我看到他们已经在帮助程序中为IE做出了特殊规定。

If you have any ideas please let me know. 如果您有任何想法,请告诉我。 Thank you. 谢谢。

Frankly I am not sure why we bothered with a helper for downloads in code igniter. 坦白说,我不确定为什么我们要麻烦一个帮助程序来下载代码点火器。

It's not entirely hard to do in pure php: 用纯PHP并不是很难:

This Wonderful Question/Answer outlines how to do it quite nicely. 这个奇妙的问题/答案概述了如何做得很好。

The real thing to remember is the content-disposition: attachment part of the headers. 要记住的真正content-disposition: attachment是标题的content-disposition: attachment部分。 It's what tells the browser that the file should be downloaded & saved vs. trying to show it in the browser. 它告诉浏览器应该下载并保存文件,而不是试图在浏览器中显示文件。

All browsers handle things differently, maybe you have something in your IE install that's overriding the behaviour but if you follow the instructions in the linked article, you should get files downloaded correctly in all browsers. 所有浏览器的处理方式都不同,也许IE安装中有一些功能可以覆盖该行为,但是如果您按照链接文章中的说明进行操作,则应该在所有浏览器中正确下载文件。

Essentially there are 3 things we need to tell the browser: 基本上,我们需要告诉浏览器三件事:

  • Content Type 内容类型
  • File Name 文档名称
  • How to treat the incoming data 如何处理传入的数据
  • (Optional Fourth, if you have it) File Size (Content-Length) (如果有的话,是可选的第四个)文件大小(内容长度)

Then you just dump that data right out to the output buffer. 然后,您只需将该数据直接转储到输出缓冲区即可。

Response 响应

In response to your replies, it's probably a security feature to not automatically download something in a popup window, probably one of the new things IE introduced to combat their previous security holes. 作为对您的答复的回应,不自动在弹出窗口中下载内容可能是一项安全功能,这可能是IE引入的旨在解决其先前安全漏洞的新功能之一。

Well I have found atleast a temporary fix for the problem. 好吧,我至少找到了解决该问题的临时方法。 All my links for force downloads were target _blank..once I created standard non pop out links the file downloads worked in IE. 我所有用于强制下载的链接都是目标_blank..。一旦我创建了标准的非弹出链接,文件下载在IE中就可以使用了。 There is probably some type of work around but I just also realized there is really no need for a pop up window for the download anyway..the download dialog box already serves that purpose. 可能有一些解决方法,但是我也意识到,确实确实不需要弹出窗口来进行下载。.下载对话框已经达到了这个目的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM