php強(qiáng)制下載文件函數(shù)
更新時(shí)間:2016年08月24日 09:23:45 作者:別安駒
這篇文章主要為大家詳細(xì)介紹了php強(qiáng)制下載文件函數(shù),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
本文實(shí)例為大家分享了php強(qiáng)制下載文件函數(shù),供大家參考,具體內(nèi)容如下
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 '文件不存在!';
}
}
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
您可能感興趣的文章:
相關(guān)文章
Search File Contents PHP 搜索目錄文本內(nèi)容的代碼
這個(gè)類可以用來搜索在給定的文本目錄中的文件。它可以給定目錄遍歷遞歸查找某些文件擴(kuò)展名的文件。2010-02-02
配置php.ini實(shí)現(xiàn)PHP文件上傳功能
為大家介紹下在php.ini文件中配置php文件上傳功能的方法,涉及到一些重要的選項(xiàng),關(guān)系到php上傳文件大小的限制等,有需要的朋友參考下2014-11-11
php自定義時(shí)間轉(zhuǎn)換函數(shù)示例
這篇文章主要介紹了php自定義時(shí)間轉(zhuǎn)換函數(shù),可實(shí)現(xiàn)時(shí)間戳與字符串時(shí)間顯示格式之間的轉(zhuǎn)換功能,需要的朋友可以參考下2016-12-12

