2011-05-22 25 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

答えて

3

「ありがとう」ページにリダイレクトされ、すぐに「強制ダウンロード」ページにリダイレクトされます。これでダウンロードは開始されますが、ユーザーは「ありがとう」ページに残ります。

UPDATE: 代わり

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

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

を変更してみてください。

+0

これは確かにそれを行う自然な方法です。 –

+0

私がしなければ、この 'IF($クエリ=の$ this - > brochure_model-> addContact()) \t \t \t { \t \t \t \tリダイレクト( '/ありがとう/ダウンロード'); \t \t \t \t redirect( '/ download/thassos_wonder_brochure'); \t \t \t \t \t \t \t} \tは 'それはお礼のページが、ノーダウンロードをロードします。ありがとうございましたページのすべてのコードの最後にリダイレクトを追加すると、ダウンロードのみが強制されますが、あなたのページにリダイレクトされません。 – strangeloops

+0

同じページでリダイレクトすることはできません。あなたは「おはよう」ページにリダイレクトし、そのページをダウンロードページにリダイレクトさせる必要があります。 – Repox

関連する問題