好的,我有以下 php 文件:
<?php
header("Content-Type: application/octet-stream");
$file = $_GET["file"];
header("Content-Disposition: attachment; filename=" . urlencode($file));
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-Description: File Transfer");
header("Content-Length: " . filesize($file));
$file = "pdf/".$file;
flush(); // this doesn't really matter.
$fp = fopen($file, "r");
while (!feof($fp)) {
echo fread($fp, 65536);
flush(); // this is essential for large downloads
}
if ($file="pdf/sampleFile.pdf") {
?>
<html>
<head>
<title>Best Recipes Ever!</title>
<link rel="stylesheet" href="style/style.css" />
</head>
<body>
<div id="header">
<h1>Best Recipes Ever!</h1>
</div>
<div id="page">
<h1>Thank You For Your Download!</h1>
<p>I sincerely hope that you enjoy this free recipe! If satisfied, please feel free to return and purchase some of my recipes. Trust me, you won't regret it!</p>
</div>
</body>
</html>
<?php
}
fclose($fp);
?>
这个想法是,如果它是示例文件,它会下载文件然后重定向到感谢页面。但是,如果它是付费下载,则此文件仅下载文件,但不执行任何操作(因为它们来自的页面是已购买下载文件链接的列表,因此它需要保留在该页面上)。
然而,这个页面正在做的是下载文件但不重定向。我究竟做错了什么?我该如何解决?