This article mainly introduces php mandatory file download functions, which has some reference value. interested friends can refer to the examples in this article to share with you the php mandatory file download function, for your reference, the specific content is as follows:
Public function down () {$ id = $ this-> _ get ('id'); $ M = M ("downloads "); $ data = $ M-> where ("id = $ id and status = 1")-> find ();! $ Data & exit; $ filename = iconv ('utf-8', 'gbk', $ data ['filename']); $ savename = $ data ['savename']; $ myfile = $ data [url]? $ Data [url]: 'uploads/file /'. $ savename; if (file_exists ($ myfile) {$ M-> where ("id = $ id")-> setInc ('downloads '); $ file = @ fopen ($ myfile, "r"); header ("Content-type: application/octet-stream"); header ("Content-Disposition: attachment; filename = ". $ filename); while (! Feof ($ file) {echo fread ($ file, 50000) ;}fclose ($ file); exit;} else {echo 'The file does not exist! ';}}
The above is all the content of this article. I hope it will help you learn and support PHP.
For more articles about force download of file functions in php, please follow the PHP Chinese network!