我有一個表單,當我驗證我想重定向用戶到謝謝頁,然後強制下載文件 這裏發生了什麼是重定向用戶到下載頁面(空白頁),然後下載開始..當我刪除重定向功能的「刷新」它下載的文件即時 這裏是我的代碼在Codeigniter強制下載,然後留在感謝頁
控制器
public function index()
{
if ($this->form_validation->run('price') == FALSE) {
// Validation problems
$this->load->view('control_front', array('page' => 'price'));
}
else
{
redirect('price/thanks', 'refresh');
}
}
public function download()
{
$this->load->helper('download');
$data = file_get_contents("./uploads/price-list-2013.pdf"); // Read the file's contents
$name = 'pricelist.pdf';
force_download($name, $data);
// doesn't go the view page
$this->load->view('control_front', array('page' => 'thanks'));
}
我需要做什麼是加載謝謝頁然後fo rce下載..我該怎麼做?
您將需要使用JavaScript。如果你擔心javascript關閉的人(這很少),你可以添加一個鏈接,說「如果你的下載沒有自動開始,請點擊這裏」 – jah 2013-05-02 12:36:43