Okay, I have the following php file:
<?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);
?>
The idea is, if its the sample file, it downloads the file then redirects to a thank you page. However, if its a paid-for download(s), this file only downloads the files, but does nothing (because the page they are coming from is a list of purchased download file links, so it needs to stay on that page).
What this page is doing, however, is downloading the file but doesn't redirect. What am I doing wrong? And how can I fix it?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…