If we only use & lt; ahref & amp; #39; file path/file name & amp; #39; & gt; download & lt;/a & gt; or js window. location & amp; #39; file path/file name & amp; #39; and the file type is recognizable by the browser, the browser will open the file directly instead of pop-up the download box to download the file, for example...
If we only use the download or js window. location = 'File path/upload', '. Conf','. bin', and so on. Of course, the document.execcommand('saveas', 'mycodes.txt ') (the second parameter is the file name to be saved) of JS can also be downloaded, but its compatibility is poor and firefox is invalid. If your environment supports the php language, you can use header () to download files:
Let's look at a simple example first:
There are two files in the same directory: index.php, test.php, and the download file adam.txt:
Test. php file content:
$ Filename = 'adam.txt ';
Echo "download ";
?>
Index. php file content:
$ 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 perform a single download, you can download the adam.txt file.
Likewise, we can download files such as .jpg, .zip, .rar, and plain. in this case, we only need to modify the header ("Content-Type: text/plain") in index. php, as shown below:
Header ("Content-Type: application/zip"); // zip or rar
Header ("Content-Type: application/pdf"); // pdf
Header ("Content-Type: image/jpeg"); // image
Header ("Content-Type: audio/mpeg ");
From adamboy