[thelist] Force file download from browser?

phil phil at xlab.co.uk
Fri May 17 10:06:01 CDT 2002


> How do you set the MIME type of the document or link to
> application/octet-stream?"

If you can use PHP, you can do this through the header() function - you
would pass $file to a page containing the code below - e.g.
<a href="download.php?file=foobar.mp3">download foobar</a>

the PHP code in download.php :

<?php

urlencode($file) ."\";',1000);";

$f = @fopen($file,"r");
if (!$f)
    print "<HTML><BODY>Failed to download $file</BODY></HTML>";
else
    {
    header("Content-Type: application/octet-stream");
    header("Content-Length: ".filesize($file));
    header("Content-Disposition: attachment; filename=" .basename($file));
    $data="";
    while (!feof($f)) $data.=fread($f,64000);
    fclose($f);
    print $data;
    }
?>

hope this helps - I found sometimes IE on Mac will still open the file,
but fine elsewhere...

Phil




More information about the thelist mailing list