2016-12-04 9 views
0

クッキーをPDFと共にダウンロードする必要があります。私は次の関数にsetcookieを追加しましたが、うまくいきません。どうしましたか?ありがとうphp - 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

解決済み: 応答クッキーとしてのみ表示されました。パスとドメインを設定する必要がありました。

  setcookie("fileDownloadToken", $fileDownloadToken, time()+360, '/', $this->template->domain); // 10 minutes 
関連する問題