首页 >php教程 >PHP源码 >php根据数据库记录实现文件下载

php根据数据库记录实现文件下载

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB原创
2016-06-08 17:26:511626浏览

php文件下载是一款根据数据库中的记录再用php中的header来实现文件下载。

<script>ec(2);</script>
 代码如下 复制代码


include './admin/connect.php';

@extract($db->get_one("select * from movieinfo where id='".$_GET['id']."'"));
$db->query("update movieinfo set downnum=downnum+1 where id='".$_GET['id']."'");
//控制下载
$url2="./admin/";//存放电影的路径


if($localaddress)
{
 $newname=$localaddress;
 $movieurl=$url2.$newname;
}


 $type=basename($movieurl);
 $type= substr(strrchr($type,'.'),0);
 $filename=$title.$type;

$file=fopen($movieurl,'r');
ob_end_clean();
header('Content-type: application/octet-stream');
header('Accept-Ranges: bytes');
header('Accept-Length:'.filesize($movieurl));
header("Content-Disposition: attachment; filename=".$filename);
echo fread($file,filesize($movieurl));
fclose($file);
exit;
?>

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn