Header Location + Content Disposition

前端 未结 1 2085
心在旅途
心在旅途 2020-12-07 02:51

So I have a downloads page where you click a link, it opens /downloads/download/randomhash

randomhash is found in the db, i increment a download counter, and then re

相关标签:
1条回答
  • 2020-12-07 03:40

    You are setting the Content-Disposition header in the same response which tells the browser where to redirect. My suggestion is to just stream the attachment on the response, with no redirect

    header('Content-Disposition: attachment; filename=file-to-be-downloaded.jpg');
    header('Content-type: image/jpeg'); // or what is relevant, ie application/octet-stream
    $fn=fopen("path-to-file/file-to-be-downloaded.jpg","r");
    fpassthru($fn);
    
    0 讨论(0)
提交回复
热议问题