Codeigniter:下载文件并重定向 [英] Codeigniter: download file and redirect

查看:85
本文介绍了Codeigniter:下载文件并重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在此页面上有一个表格 http://www.obsia.com/products/thassos_wonder_brochure/
点击提交时,我希望它开始下载文件,并重定向到谢谢页面。但是我只能下载文件或重定向或加载感谢下载页面。

I have a form on this page http://www.obsia.com/products/thassos_wonder_brochure/ On hitting submit, I want it start downloading the file and also get redirected to thank you page. But I can only get it either download the file or redirect or load the thank for downloading page.

这是检查表单并提交的功能:

This is the function for checking the form and submiting:

function thassos_wonder_brochure()
{
    $this->load->helper('form');
    $this->load->helper('email');
    $this->load->library('email');
    $this->load->library('form_validation');

    //form validation
    $this->form_validation->set_rules('firstname', 'First Name', 'required|max_length[32]');
    $this->form_validation->set_rules('lastname', 'Last Name', 'required|max_length[32]');
    $this->form_validation->set_rules('companyemail', 'Company Email', 'required|max_length[100]|valid_email|unique');

    $this->load->model('brochure_model');
    if ($this->form_validation->run() == FALSE) 
    {
        // redisplay user form and repopulate fields
        $this->load->view('/tw/thassos_wonder_brochure_view');
    }   
    //display confirmation web page and send email
    else
    {   

        if($query = $this->brochure_model->addContact())
        {
            redirect('/thankyou/thassos_wonder_download');  (UPDATE)    
        }   
    }

}

下面的代码在谢谢页面上,以重定向到下载页面结尾:(UPDATE)

Below is the code is on the thank you page ending with redirect to the download page: (UPDATE)

    <?php $this->load->view('header_view.php'); ?>
    <div class="prod">
    <?php $this->load->view('pmenu_view');?>

<div class="product_desc" id="tw_download">
    <h1>Thank you for Downloading</h1>
    <p>You have downloaded the brochure for ThassosWonder - for white stones specifically. You will also receive further information and link to the downloads in your email after you click on the confirmation link in your email.</p>
    <?php echo br(1); ?>
    <p>Feel free to write to us, if you are unable <?php echo anchor('contact', 'to get desired finish from your white marble or stones')?>. You can upload a picture to get a thorough analysis from our Research Director.</p>
    <br />

</div>
    </div>
    <?php $this->load->view('footer_view');?>  
<?php redirect('download/thassos_wonder_brochure'); ?>

这是我在下载页面上使用的代码。

This is the code I used on the download page. How can I download the file and also redirect it to thank you page.

<?php 
$this->load->helper('download');
$name = 'ThassosWonder.pdf';
$data = file_get_contents("./downloads/brochures/Thassos_Wonder_Obsia.pdf"); // Read the file's contents - cannot use relative path. It will try to call the file from same directory (controller) as this file. In order for it get the contents from the root folder put a . in front of the relative path//
force_download($name, $data); 
 ?>

任何帮助将不胜感激。

推荐答案

执行另一种方法-重定向到谢谢页面,然后立即重定向到强制下载页面。这将开始下载,但将用户保留在谢谢页面上。

Do it the other way around - redirect to the 'thank you' page and immediately redirect to the 'force download' page. This will start the download but leave the user on the 'thank you' page.

更新:
尝试更改

UPDATE: Try changing

<?php redirect('download/thassos_wonder_brochure'); ?>

<?php redirect('download/thassos_wonder_brochure', 'refresh'); ?>

这篇关于Codeigniter:下载文件并重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆