If we use only download or JS window.location = ' file path/filename ' and the file type is browser-aware, then the browser will open the file directly instead of the popup download box to download the file, such as '. txt ', '. conf ', '. bin ' file, etc. Of course JS Document.execcommand (' SaveAs ', ' Mycodes.txt ') (the second parameter is to be saved as the file name) can also be downloaded, but its compatibility is not good, Firefox invalid. If your environment supports the PHP language, then you can use the header () to implement the file download:
Let's look at a simple example:
There are two files in the same directory index.php,test.php with adam.txt for downloading files:
test.php File Contents:
$filename = $filename = ' Adam.txt ';
echo "Download";
?>
index.php File Contents:
$filename = $_request[' filename '];
Header ("Content-type:text/plain");
Header (' content-disposition:attachment;filename= '. $filename);
Header (' content-transfer-encodeing:binary ');
ReadFile ($filename);
?>
When you open test.php and click Download, the download of the Adam.txt file will be implemented.
In the same vein, we can also implement the download of files such as. Jpg,.zip,.rar,.pdf, and then simply modify the header ("Content-type:text/plain") in the index.php, as shown below
Header ("Content-type:application/zip");//zip or rar
Header ("Content-type:application/pdf");//pdf
Header ("Content-type:image/jpeg");//Picture
Header ("Content-type:audio/mpeg");
Excerpted from Adamboy
http://www.bkjia.com/PHPjc/478339.html www.bkjia.com true http://www.bkjia.com/PHPjc/478339.html techarticle If we only use a href= file path/filename to download/A or JS window.location = file path/filename, and the file type is the browser can recognize, then the browser will be directly hit ...