强制下载文件IN IE

时间:2014-12-19 11:18:59

标签: codeigniter

在IE中使用codeigniter下载文件时重定向图像路径,不显示像firefox或chrome这样的弹出窗口下载文件

我在我的控制器中使用的代码:

public function download_file($filename)
    {         
            $this->load->helper('download'); //load helper
           $data = file_get_contents('wall-images/'.$filename); // Read the file's contents
           $name = $filename;
           force_download($name, $data);    

    }

2 个答案:

答案 0 :(得分:0)

我使用javascript&它适用于所有浏览器。

<a target="_blank" class="btn btn-primary" id="download" href="#">Download File</a>

<script type="text/javascript">
jQuery(document).ready(function(){
    jQuery('#download').click(function(){
        var url = "<?php echo site_url($filename); ?>";
        document.location = url;
    });
});
</script>

答案 1 :(得分:0)

IE既不支持导航到数据URI也不支持download属性。 您可以使用navigator.msSaveBlob保存IE 10+的文件 您可以检查window.navigator.msSaveBlob并编写IE特定代码,否则使用现有代码保存文件 您可以查看以下链接了解更多详情: Saving files locally using Blob and msSaveBlob