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

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

WBOY
Release: 2016-06-08 17:26:51
Original
1623 people have browsed it

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;
?>

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template