您好我正在尝试允许下载与产品相关的演示文件。我的代码是这样的
if(isset($_POST['submit'])){
$root = $_SERVER['DOCUMENT_ROOT'];
$path = "/download/";
$path = $root.$path;
$filename = $demo;
$file = $path.$filename;
header('Content-Type: application/force-download');
header("Content-Transfer-Encoding: Binary");
header("Content-Disposition: attachment; filename=\"".basename($file)."\";" );
header("Content-Length: ".filesize($file));
readfile($file);
}
我可以通过以下方式获取与产品关联的文件名
$演示
用户提交信息后,下载将自动开始。现在这是用正确的文件名下载不存在的文件或损坏的文件。请帮忙