+316原创程序 +49收集论文 +84原创文章 +1669VIP客户 +3259809总访问量
您的位置:首页 > 设计师随笔 > 分享一个php下载文件的函数
分享一个php下载文件的函数
作者/来源:原创    时间:2018-05-17    关注4776次

原创函数,在多种场景下实测有效:

function downfile($downname,$fileurl){

$filename=$fileurl;
$temp=explode(".",$filename);
file_exists($fileurl) or die('file does not exist');
ob_clean();
header('Content-Description:File Transfer');
header('Content-Type:application/octet-stream');
header("Content-Transfer-Encoding:binary");
header("Content-Disposition:attachment;filename={$downname}.".end($temp));
        header('Expires:0');
        header('Cache-Control:no-cache,must-revalidate');
header("Pragma:no-cache");  
header('Content-Length:'.filesize($fileurl));
readfile($fileurl);
exit;

}

test.php

ob_start();

downfile("newname","G:\old.jpg");




©专业辅导 php毕业设计,php课程设计,php期末作业,php大作业,品质保证 访问:3259809次  
9laile.com源码在线销售平台由本站设计师齐工独立研发
当前版本V1.1.18
皖ICP备05020966号

皖公网安备 34072202000111号

 68813382