ngl5000
ngl5000

Reputation: 11

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. In IE it fails everytime and I get the following error: Unable to download $filename from mysite.com

Unable to open this Internet site. 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:

        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. 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.

If you have any ideas please let me know. Thank you.

Upvotes: 1

Views: 2225

Answers (2)

Aren
Aren

Reputation: 55966

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:

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. 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.

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.

Upvotes: 2

Nick
Nick

Reputation: 356

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. 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.

Upvotes: 1

Related Questions