2011-01-25 80 views
0

這是我的下載加載器控制器。第一次它正常工作。它打開保存爲彈出並能夠下載所需的文件,但下次顯示直接目錄列表。無法使用codeignitor下載文件

enter image description here

<?php 

class Download extends Controller { 

function Download(){ 
    parent::Controller(); 
    $this->load->helper('download'); 
    echo "I am in constructor"; 

} 

function index(){ 
    $file = realpath("download")."\\profile.doc"; 
    echo "I am in index."; 

     exit; 

    if (file_exists($file)) { 
     header('Content-Description: File Transfer'); 
      header('Content-Type: application/octet-stream'); 
      header('Content-Disposition: attachment; filename=' . basename($file)); 
      header('Content-Transfer-Encoding: binary'); 
      header('Expires: 0'); 
      header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); 
      header('Pragma: public'); 
      header('Content-Length: ' . filesize($file)); 
      ob_clean(); 
      flush(); 
      readfile($file); 
      exit; 
     }else{ 

    // File Not Found 

     echo "File not found"; 
     } 

} 
} 
?> 
+0

你的網址如何在「第一」和「第二」之間進行嘗試? – polarblau 2011-01-25 08:21:39

回答

3

你應該使用下載助手作爲user_guide看到。它處理這種情況。