How to force file download with PHP

后端 未结 11 1539
被撕碎了的回忆
被撕碎了的回忆 2020-11-21 23:13

I want to require a file to be downloaded upon the user visiting a web page with PHP. I think it has something to do with file_get_contents, but am not sure how

11条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-21 23:23

    header("Content-Type: application/octet-stream");
    header("Content-Transfer-Encoding: Binary");
    header("Content-disposition: attachment; filename=\"file.exe\""); 
    echo readfile($url);
    

    is correct

    or better one for exe type of files

    header("Location: $url");
    

提交回复
热议问题