Hi, I am having a problem forcing a download from PHP. I am running 5.2 Stable. I have followed numerous tutorials and still can't figure it out. What I'm trying to do is force-download a file I made, because the browser likes opening it up inside, but it won't let me use relevant paths so I have to type in the full web address every time. Here's my working and not working code:
Working:
if ($checkbox) {
$file = 'http://12.148.233.90/downloads/Tutorial1.wmv.zip';
// Set headers
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=Tutorial1.wmv.zip");
header("Content-Type: application/zip");
header("Content-Transfer-Encoding: binary");
//header("Content-Length: " . filesize($file));
ob_clean();
flush();
readfile("$file");
exit;
}
else {
...
}
Not working, but want to work:
if ($checkbox) {
$file = 'downloads/Tutorial1.wmv.zip';
// Set headers
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=Tutorial1.wmv.zip");
header("Content-Type: application/zip");
header("Content-Transfer-Encoding: binary");
header("Content-Length: " . filesize($file));
ob_clean();
flush();
readfile("$file");
exit;
}
else {
...
}
With the not working code section, it says that it can't find the file. The reason I want that section working is because I want the file size to be correct when you download (so it doesn't say "Unknown Time Remaining") and to simplify the code a little bit. Thanks for your help.
If you need me to clarify anything, just ask. I could also map my HDD and upload my IIS settings too.