Click to See Complete Forum and Search --> : [RESOLVED] Downloading Content Outside Webroot . . .


misteralexander
10-26-2008, 09:51 AM
Hello All,

Okay, so I've got a script here:

<?php

######################################################
# Script Found Via Google On: #
# http://www.haroldbakker.com/php/listing.php #
# For Use On http://*.wickedsmaat.com #
# No Requst Or Permission Was Made / Granted For Use #
######################################################

?>
<table border="1" cellspacing="0" cellpadding="2">
<?php
function usecolor()
{
static $colorvalue;

$trcolor1 = "grey1";
$trcolor2 = "grey2";

if($colorvalue == $trcolor1)
$colorvalue = $trcolor2;
else
$colorvalue = $trcolor1;
return($colorvalue);
}


function test()
{
$default_dir = "./";
if(!($dp = opendir($default_dir))) die("Cannot open $default_dir.");
while($file = readdir($dp)) $filenames[] = $file;
closedir($dp);
sort($filenames);
echo "<tr><th>Files</th></tr>\n";
for($i=0; $i < count($filenames); $i++)
{
if($filenames[$i] != 'listing.php' && !preg_match('/^\./',$filenames[$i]) && !is_dir($filenames[$i]))
// don't show directories, listing.php and files that start with a dot
echo "<tr><td class=\"" . usecolor() . "\"><a href=\"" . rawurlencode($filenames[$i]) . "\">". $filenames[$i] . "</a></td></tr>\n";
}
echo "<tr><th>Directories</th></tr>\n";
for($i=0; $i < count($filenames); $i++)
{
if (is_dir($filenames[$i]) && !preg_match('/^\./',$filenames[$i]))
// do show directories but not files and exclude everything that starts with a dot
echo "<tr><td class=\"" . usecolor() . "\"><a href=\"" . rawurlencode($filenames[$i]) . "\">". $filenames[$i] . "</a></td></tr>\n";
}
}

test();
?>
</table>


The line in there that makes the filesnames into Hyperlinks is:
echo "<tr><td class=\"" . usecolor() . "\"><a href=\"" . rawurlencode($filenames[$i]) . "\">". $filenames[$i] . "</a></td></tr>
Well, instead of making them into plain old hyperlinks, i'm wondering how I can make it so the hyperlink generated, sends them to my "Download.php" file, listed below:

<?php
// Creating a "Force-Download" for media files
// What MIME data type is it?
header('Content-type: application/octet-stream');
// What do you want the file to be called?
header('Content-Disposition: attachment; filename="FILENAME.GOESHERE"');
// The Original Source Of The File
readfile('FILENAME.GOESHERE');
?>


Furthermore, how do you make the "Download.php" file dynamic, so it applies to all files sent it's way and not just the one defined in the header & readfile lines?

Don't get me wrong, I'm not asking for someone to do it for me . . . I'm just wanting someone to push me in the right direction . . . what do I need to be researching & looking at for this to work the way I'm wanting?

Any help at all, is still help . . . thanks!:D