Codeigniter Force下载不起作用

时间:2016-07-16 09:33:59

标签: codeigniter continuous-integration

使用codeigniter 2.2.6进行开发。现在已经一年了,我无法使用此代码http://pastebin.com/0jL4dj90从服务器下载PDF文件,任何帮助都将受到赞赏。感谢

1 个答案:

答案 0 :(得分:0)

解决。我已经设法通过使用此函数找到了解决此问题的方法

function _push_file($path, $name){
  // make sure it's a file before doing anything!
  if(is_file($path))
  {
    // required for IE
    if(ini_get('zlib.output_compression')) { ini_set('zlib.output_compression', 'Off'); }

    // get the file mime type using the file extension
    $this->load->helper('file');

    $mime = get_mime_by_extension($path);

    // Build the headers to push out the file properly.
    header('Pragma: public');     // required
    header('Expires: 0');         // no cache
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header('Last-Modified: '.gmdate ('D, d M Y H:i:s', filemtime ($path)).' GMT');
    header('Cache-Control: private',false);
    header('Content-Type: '.$mime);  // Add the mime type from Code igniter.
    header('Content-Disposition: attachment; filename="'.basename($name).'"');  // Add the file name
    header('Content-Transfer-Encoding: binary');
    header('Content-Length: '.filesize($path)); // provide file size
    header('Connection: close');
    readfile($path); // push it out
    exit();
    }
}
相关问题