我有一个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);
?>
您应该像这样使用
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");