2

我有一个 PHP 脚本,它应该允许用户在不显示 URL 的情况下下载文件。当我尝试以下内容时,我下载的文件是空的。有人可以帮忙吗?

<?php
$file_name = 'test.exe';
$file_url = 'https://www.example.com/' . $file_name;
header('Content-Type: application/octet-stream');
header("Content-disposition: attachment; filename=".$file_name); 
readfile($file_url);
?>
4

1 回答 1

2

你应该这样使用

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

还基于您的文件应用程序/zip、应用程序/pdf 等的内容类型

AND或更好的exe

header("Location: $url");
于 2013-07-26T05:24:57.247 回答