0

我有一个表格,当我验证时我想将用户重定向到感谢页面然后强制下载文件这里发生的事情是将用户重定向到下载页面(空白页面)然后下载开始..当我删除来自重定向功能的“刷新”它会立即下载文件这是我的代码

控制器

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'));

}

我需要在这里做的是加载感谢页面然后强制下载..我该怎么做?

4

1 回答 1

0

I usually use this function in js file, inside setTimeout for delay X seconds. You can put this code, with file route, in php view.

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;  
}


于 2013-05-02T08:47:32.537 回答