I'm creating html links to files on my server, however when I click the links I do not get a popup window asking for Save or download dialog like this one:
I want to get that window when i click on the links.
Here's the code I'm using:
<?php
listDirectory(".");
function listDirectory($path)
{
$handle = @opendir($path);
while (false !== ($file = readdir($handle)))
{
if ($file == '.' || $file == '..') continue;
if ( is_dir("$path/$file"))
{
print ("<a href=\"$path/$file\">$path/$file</a>");
}
else
{
print ("<a href=\"$path/$file\">$path/$file</a>");
}
}
closedir($handle);
}
?>
Note: print ("$path/$file"); ~ works only for particular browser only ( not for IE ) and Directory download cannot be done
If you do not need to support old Browsers, you can use the HTML5 download attribute.
If support for non-HTML5-Browsers is needed, you can use PHP to force the browser to download the file using a custom set header:
Content-disposition: attachment; filename=my_file.extension
Content-Type: application/octet-stream
Sending the application/octet-stream content type doesn't allow the browser to display the document (e.g., if it is an iname or something else the browser can display itself).