This example for you to share the PHP mandatory download file function for your reference, the specific contents are 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 entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.