2011-05-22 46 views
2

我在這個頁面上有一個表格http://www.obsia.com/products/thassos_wonder_brochure/ 在提交時,我希望它開始下載文件,並且也被重定向到感謝頁面。但我只能得到它下載文件或重定向或加載謝謝下載頁面。Codeigniter:下載文件並重定向

這對於檢查的形式和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)

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

這是我在下載頁面上使用的代碼。我如何下載該文件並將其重定向到感謝頁面。

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

任何幫助將不勝感激。

+0

我已經更新了答案... – Repox 2011-05-25 07:58:36

回答

3

反其道而行 - 重定向到「謝謝」頁面,並立即重定向到「強制下載」頁面。這將開始下載,但將用戶留在「謝謝」頁面上。

UPDATE: 嘗試改變

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

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

代替。

+0

這當然是做到這一點的自然方法。 – 2011-05-23 05:11:10

+0

如果我這樣做'如果($查詢= $這個 - > brochure_model->的addContact()) \t \t \t { \t \t \t \t重定向( '/三江源/下載'); \t \t \t \t重定向('/ download/thassos_wonder_brochure'); \t \t \t \t \t \t \t} \t'然後將其裝入感謝您網頁,但沒有下載。如果我在所有代碼的最後添加重定向以表示感謝頁面,則它只會強制下載,但不會將其重定向到感謝頁面。 – strangeloops 2011-05-23 19:46:39

+0

你不能在同一頁面重定向。您必須重定向到「謝謝」頁面並讓該頁面重定向到下載頁面。 – Repox 2011-05-24 06:51:38