如何使用PHP强制下载文件

如何使用PHP强制下载文件

我想要求在使用PHP访问网页的用户上下载一个文件。我想这和file_get_contents,但不知道如何执行。

$url = "http://example.com/go.exe";

下载文件之后,header(location)它不会重定向到另一个页面。就这样停了下来。


饮歌长啸
浏览 766回答 3
3回答

万千封印

header("Content-Type: application/octet-stream");header("Content-Transfer-Encoding: Binary"); header("Content-disposition: attachment; filename=\"file.exe\""); echo readfile($url);是正确的或者更好的EXE文件类型header("Location: $url");
打开App,查看更多内容
随时随地看视频慕课网APP