Force Download

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
xQuasar
Forum Newbie
Posts: 19
Joined: Tue Dec 02, 2008 5:53 pm

Force Download

Post 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
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Force Download

Post 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.
Post Reply