2013-04-23 76 views
2

我必須下載它放在一個文件中的一些數據的笨功能。下載文件PHP

$data= "test"; 

header('Content-Disposition: attachment; filename=test.file'); 

echo $data; 

但是,內容包括該視圖的HTML,在該視圖中我單擊以激活該函數。如何刪除文件中的HTML內容?

+1

嘗試把一個'出口(;'後立即回波 – keithhatfield 2013-04-23 15:57:35

+0

NICE!謝謝!有用 – edelweiss 2013-04-23 16:00:48

回答

1

只是對於文件創建單獨的控制器/視圖。

0

在控制器中創建方法

示例代碼:

public function download_file($name) 
    { 
     $data = file_get_contents(FCPATH . 'storage' . DIRECTORY_SEPARATOR. $name); // Read the file's contents 

     force_download($name, $data); 
     redirect('index/index'); 
    } 

呼叫從視圖頁)上述方法