2010-03-27 48 views
1

現在我得到了這段代碼;如何在下載框出現時重定向頁面?

<?php 

$file = "pain.png"; 

if (file_exists($file)) { 
    header('Content-Description: File Transfer'); 
    header('Content-Type: application/octet-stream'); 
    header('Content-Disposition: attachment; filename='.basename($file)); 
    header('Content-Transfer-Encoding: binary'); 
    header('Expires: 0'); 
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); 
    header('Pragma: public'); 
    header('Content-Length: ' . filesize($file)); 
    ob_clean(); 
    flush(); 
    readfile($file); 
    exit; 
} 
?> 

此代碼出現在下載框中。但我想將此頁面重定向到「謝謝」頁面,而下載框仍在此處。我怎樣才能做到這一點?

謝謝...

回答

0

由於下載 HTTP響應,無法從下載響應中做到這一點。你可以重定向他們,然後說「謝謝,你的下載將會發生」等等。這似乎是大多數地方的標準解決方案。

要清楚,謝謝頁面將重定向到下載URL。

2

你可以做到這一點的使用元刷新(http://en.wikipedia.org/wiki/Meta_refresh

你會從你的網頁鏈接到您的下載頁面這樣。

的index.html

<html><head></head><body> 
Download my awesome <a href="download.html">file</a> 
</body></html> 

download.html

<html> 
     <head> 
     <meta http-equiv="refresh" content="0;url=http://example.com/download.php" /> 
     </head> 
     <body> 
     Thanks for choosing Foobar! Your download will begin shortly. 
    If you're download does not begin, 
click <a href="http://www.example.com/download.php">here</a> 
     </body> 
     </html> 
相關問題