This article example for everyone to share the PHP mandatory download file functions for your reference, the specific content 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 ' file does not exist! '; }}
The above is the whole content of this article, I hope that everyone's learning has helped, but also hope that we support topic.alibabacloud.com.