I am making a file hosting website and am about 95% done but have one issue. When the user clicks their file to download it, the file just appears in the browser. I need to know a way where I can define the $file
variable in the while
loop to be downloadable. The variable that I need to make downloadable is surrounded by asterisks(*)
LOOP:
$directory = 'uploads/' . $_SESSION['user'] . '/';
if ($handle = opendir($directory)) {
echo '<h3>Your files are listed below</h3>';
while ($file = readdir($handle)) {
if ($file != '.' && $file != '..') {
echo '<a href="'.$directory.'/'.$file.'">' . *$file*.'<br>';
}
}
}
Usually every non-text file is downloaded automatically. For textfiles, you need to specify the header at the beginning of your script:
You need redirect your users to a second script to handle request:
download.php?file=somepath/somefile.ext
Your link will be:
This will performs on onclick, with confirmation alert box,
the issue is header, check the link for more information:
http://en.wikipedia.org/wiki/List_of_HTTP_header_fields