I'm trying to force a download of a protected zip file (I don't want people to access it without logging in first.
I have the function created for the login
and such , but I'm running into a problem where the downloaded file is corrupting.
Here's the code I have:
$file='../downloads/'.$filename;
header("Content-type: application/zip;
");
header("Content-Transfer-Encoding: Binary");
header("Content-length: ".filesize($file).";
");
header("Content-disposition: attachment; filename="".basename($file).""");
readfile("$file");
exit();
Here's the error: Cannot open file: It does not appear to be a valid archive.
The file downloads fine otherwise, so it must be something I'm doing wrong with the headers.
Any ideas?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…