我有一个表单,当我验证我想将用户重定向到感谢页面然后强制下载该文件 这里发生的是将用户重定向到下载页面(空白页面)然后下载开始..当我从重定向功能中删除'刷新'时,它立即下载文件 这是我的代码
控制器
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'));
}
我需要做的是加载感谢页面然后强制下载..我该怎么做?
答案 0 :(得分:0)
我通常在js文件中使用此函数,在setTimeout内使用延迟X秒。 您可以在php视图中使用文件路径放置此代码。
function downloadURL(url)
{
var iframe;
iframe = document.getElementById("hiddenDownloader");
if (iframe === null)
{
iframe = document.createElement('iframe');
iframe.id = "hiddenDownloader";
iframe.style.visibility = 'hidden';
document.body.appendChild(iframe);
}
iframe.src = url;
}