Reputation: 12462
On my web server, I have a bat (harmless) file.
And I have code,
<a href="test.bat" title="Bat">Test Bat File</a>
But when the user clicks, it shows the code instead of downloading the file.
You have to right click "save as.." to download the bat file.
Is there way that when a user clicks, it downloads (not having to right click save as)?
Maybe a pop up window that asks user if he/she wants to download the file or not?
Upvotes: 2
Views: 2093
Reputation: 91
You can do so through setting the file in the PHP header() function.
It is explained here: How to Automatically Start a Download in PHP?
Upvotes: 0
Reputation: 496
you could write a php file, which adds a content-disposition header, sets the mime type to something binary and echo the files content.
Example:
file.php
$batchfile = file_get_contents('batchlocation');
$size = strlen($batchfile);
header('Content-Disposition: attachment; filename="downloaded.bat"');
header('Content-Type: BAT MIME TYPE or something like application/octet-stream');
header('Content-Lenght: '.$size);
echo $batchfile;
Upvotes: 4