2011-01-25 26 views
0

これは私のダウンローダコントローラです。初めて正常に動作します。それはポップアップとして保存を開き、必要なファイルをダウンロードすることができますが、次回は直接のディレクトリリストを表示します。 user_guideに見られるように、あなたがダウンロードヘルパーを使用する必要があります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

"first"と "second"の間でURLがどのように変化しますか? – polarblau

+0

あなたのコメントを理解していません – Vicky

+4

CodeIgniterは自分のダウンロードヘルパーを持っていることを知っておくと便利です - http://codeigniter.com/user_guide/helpers/download_helper.html – BrynJ

答えて

3

。このような状況を扱っています。

関連する問題