我的問題是:重定向後的文件下載
按我的頁面上的鏈接將(通過稱爲PHP文件)調用,這將下載從我的web文件的功能。這意味着頭文件信息是在文件下載時發送的,這也意味着我無法調用php頭函數將BACK重定向到我的初始頁面,在那裏我點擊了開始處的鏈接。爲什麼我想回到那個頁面,是因爲它會更新我的最新下載文件的歷史記錄,但不會在文件下載之前更新。
克服這個障礙的最佳方法是什麼?
我的功能,啓動下載:
public function downloadAuthorityRules($api_key,$id)
{
$curl_post_data = array('id' => $id);
$headers = array('Content-type: application/json','Authorization: '.$api_key,);
$fp = fopen (dirname(__FILE__) . '/localfile.tmp', 'w+');//This is the file where we save the information
$curl = curl_init(DOWNLOAD_AUTHORITYRULES);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($curl_post_data));
curl_setopt($curl, CURLOPT_USERPWD, $api_key);
$file = curl_exec($curl);
if ($file === false)
{
$info = curl_getinfo($curl);
curl_close($curl);
die('error occured during curl exec. Additioanl info: ' . var_export($info));
}
curl_close($curl);
header('Content-type: ' . 'application/octet-stream');
header('Content-Disposition: ' . 'attachment; filename=myndighedsregler.pdf');
echo $file;
}
爲什麼重定向?如果您有腳本提供下載的數據,請讓該腳本在開始吐出字節之前更新下載統計數據。 –
除了Marc B所說的之外,如果您立即將您的標題設置爲下載,則網站將不會離開當前頁面 - 這意味着它們不應該離開頁面,因此不需要返回。 –
在我的web服務上調用的函數將更新涉及下載的表。在下載實際執行並更新相關表之前,我無法從我的web服務請求下載文件的狀態。 – DTH