Page 1 of 1

Force Download

Posted: Thu Dec 18, 2008 11:58 pm
by xQuasar
I was wondering how you could force a file to down in a while statement in php? Ok maybe that's not the greatest explanation; maybe you guys can get it from looking at the following code:

Code: Select all

 
<?php
if ($handle = opendir("$username_saved/extras")) {
    echo "<table cellspacing=10>";
    while (false !== ($file = readdir($handle))) {
        if ($file != "." && $file != "..") {
            echo "
                <tr>
                <td width=50%>$file</td>
                <td width=25%><a href=$username_saved/extras/$file>
                DOWNLOAD</a>
                </td>
                <td width=16%></td>
                <td width=25%>DELETE</td>
                </tr>
                ";
        }
    }
    closedir($handle);
}
?>
 
How do I force them to DOWNLOAD the file no matter what file extension when they click download, instead of opening it in the browser? Thanks

Re: Force Download

Posted: Fri Dec 19, 2008 12:07 am
by requinix
You need another PHP file to do the download.

You can tell the browser to open/save the data rather than display it by using header. Take a look at example #1.