下载一次文件-文件损坏错误


Download file once - Corrupt file error

我想做的是每个用户只允许一次下载(一次访问a href)为此,我在用户表中有一个变量,当单击链接时,我会更改该变量。我使用"download.php?file=file.xxx"来完成此操作。

download.php

$file= basename($_GET['file']);
$root = "documents/rece/";
$path= $root.$file;
echo $path;
if (is_file($path))
{
   header('Content-Description: File Transfer');
   header('Content-Type: application/octet-stream');
   header('Content-Disposition: attachment; filename='.$file);
   header('Content-Transfer-Encoding: binary');
   header('Expires: 0');
   header('Cache-Control: must-revalidate');
   header('Pragma: public');
   header('Content-Length: ' . filesize($path));
   readfile($path);
}
else
      echo "File error";
   exit();
?>

我还更新了DDBB,这很有效。之后我可以显示或隐藏链接。问题是下载的文件已损坏,无法打开。我会把它和pdf或doc一起使用,也许是zip。

可能是因为这条路吗?

PDF文件,据我所知,从以下内容开始:

%PDF-1.4

你的开头是4行空白加上documents/rece/Form.pdf%PDF-1.4。很明显,你是在发布代码之前自己打印的。