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