On a php or html webpage, there is a file link on it. When you click it, how does it open the file? How does it download it? The download dialog box appears. On a php or html webpage, there is a file link on it. When you click it, how does it open the file? How does it download it? The download dialog box appears.
Reply content:
On a php or html webpage, there is a file link on it. When you click it, how does it open the file? How does it download it? The download dialog box appears.
In this way, the file is downloaded:
Function downloadfile ($ filename, $ storage) {if (! Is_file ($ storage) exit ('the file does not exist! '); If (! $ Fp = fopen ($ storage, 'R') exit ('error'); header ('content-Type: application/octet-stream; charset = UTF-8 '); if (preg_match ("/Trident/", $ _ SERVER ["HTTP_USER_AGENT"]) {header ('content-Disposition: attachment; filename = "'. utf8togbk ($ filename ). '"');} else {header ('content-Disposition: attachment; filename = "'. $ filename. '"');} header ('content-Transfer-Encoding: binary '); while (! Feof ($ fp) {echo fread ($ fp, 1025) ;}fclose ($ fp );}
Should I open a file in a browser?
You can use the php header () method to modify the content of the html header.