Page 1 of 1
[SOLVED] Force download files
Posted: Mon Sep 25, 2006 11:45 pm
by tristanlee85
I've created a downloads section on my forum and the files that are being downloaded are.msq files. Right now, if a user clicks the link to download the file, it opens the file as a text file within the browser. Can I use header() to force the file to b downloaded?
Posted: Tue Sep 26, 2006 12:03 am
by tristanlee85
Nevermind. I just had to comment something out.
Doesn't work
Code: Select all
if (isset($_GET['download']))
{
$filename = $_GET['download'];
header("Content-Type: ".get_mimetype($filename));
header("Content-Length: ".filesize($path . $filename));
header("Content-Disposition: attachment; filename=$filename");
readfile($path . $filename);
}
Does work
Code: Select all
if (isset($_GET['download']))
{
$filename = $_GET['download'];
header("Content-Length: ".filesize($path . $filename));
header("Content-Disposition: attachment; filename=$filename");
readfile($path . $filename);
}
Posted: Wed Sep 27, 2006 10:25 pm
by tristanlee85
Alright. I guess none of them work. When I click the download link for my file, I'll open it to check the source of the file and the whole source is the entire web page source. Why are my files getting saved as the web page instead of true file?
Posted: Thu Sep 28, 2006 12:34 am
by wtf
Posted: Thu Sep 28, 2006 1:01 am
by tristanlee85
What I have works. I had a quote in the wrong spot for my link and it was trying to open the file http://...file.msq%20target=.