Force browsers to download a file rather than open

后端 未结 2 1194
一向
一向 2020-12-12 02:28

I\'m using typical PHP code to download documents:

  header(\'Content-Type: \' . $mimeTypes[$fileext]); 
  header(\'Content-Disposition: attachment; filename         


        
相关标签:
2条回答
  • 2020-12-12 02:53

    Add this to your headers:

    header("Content-type: application/force-download");
    
    0 讨论(0)
  • 2020-12-12 03:06

    The following php worked for me

    header("Cache-Control: private");
    header("Content-Description: File Transfer");
    header("Content-Disposition: attachment; filename=".$file."");
    header("Content-Transfer-Encoding: binary");
    header("Content-Type: binary/octet-stream"); 
    readfile ($link);
    

    P.S. - I used the File extension in the $file variable only, so no need to mention mime type...

    Hope this helps :)

    0 讨论(0)
提交回复
热议问题