I am using the code below to list a users directory on the company intranet I am building, it basically creates a bullet list of the users directory.
What I want to do is put a link after every file so that the user can download it, my code below does this and if I hover over the link the correct url is displayed, the link is pointing towards download.php which handles the file with headers so whatever the file the browser is forced to show the download box.
But when I click the link the download box appears but in it the file name says download.php.
<?php
include("../username/username.php");
$dir_name = "E:/uploads/$username/";
$dir = opendir($dir_name);
$file_list = "<ul>";
while ($file_name = readdir($dir)) {
if (($file_name != ".") && ($file_name != "..") && ($file_name != "Thumbs.db")) {
$file_list .= "<li>$file_name<a href='download.php?file_name=$file_name'> Download</a><br><br>";
}
}
$file_list .= "</ul>";
closedir($dir);
?>
<? echo "<p>$username, you have the recieved the following Files :"; ?>
<? echo "$file_list"; ?>
It seems that download.php is not recieving the correct information, ie : the filename.
Also if possible can someone tell me how to remove the extensions off of the list, ie : "text.doc" displays as "text".
My download.php looks like this :
<?php
header("Content-Type: application/force-download");
header("Content-Disposition: attachment; filename=$file_name");
print "$file_name";
?>
Can anybody help me with this ?
Any help would be greatly appreciated.