Force browsers to download a file rather than open

后端 未结 2 1204
一向
一向 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条回答
  •  Happy的楠姐
    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 :)

提交回复
热议问题