2016-12-04 35 views
0

我需要與PDF一起下載一個cookie。我將setcookie添加到以下函數,但它不起作用。怎麼了?由於php - 下載一個cookie連同pdf

protected function send_download($file) { 
    if (file_exists($file)) { 
     set_time_limit(0); 
     header('Connection: Keep-Alive'); 
     header('Content-Description: File Transfer'); 
     header('Content-Type: application/octet-stream'); 
     header('Content-Disposition: attachment; filename="'.basename($file).'"'); 
     setcookie("fileDownloadToken", "fileDownloadToken", time()+360); // 10 minutes 
     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); 
    } 
} 

回答

0

解決:) 這是可見的只是作爲響應的cookie。有必要設置路徑和域。

  setcookie("fileDownloadToken", $fileDownloadToken, time()+360, '/', $this->template->domain); // 10 minutes