?? downfile.php
字號:
<?php
##
# Project: PHPDisk
# This is NOT a freeware, use is subject to license terms.
#
# Site: http://www.phpdisk.com
#
# $Id: downfile.php 269 2009-03-11 08:50:36Z along $
#
# Copyright (C) 2008-2009 PHPDisk Team. All Rights Reserved.
#
##
include "includes/commons.inc.php";
$chunk = 16384;
@set_time_limit(0);
@ignore_user_abort(true);
@set_magic_quotes_runtime(0);
function alert($f){
header('Content-type: image/gif');
@readfile($f);
exit;
}
$action = trim(gpc('action','G',''));
$file_key = gpc('file_key','G','');
$file_id = (int)gpc('file_id','G',0);
if($action =='public'){
$rs = $db->fetch_one_array("select * from pd_publics where file_id='$file_id' and file_key='$file_key'");
if($rs){
$file_real_name = $rs['file_real_name'];
$tmp_ext = $rs['file_extension'] ? '.'.$rs['file_extension'] : "";
$file_name = $rs['file_name'].$tmp_ext;
$file_extension = $rs['file_extension'];
$file_mime = $rs['file_mime'];
$file_size = $rs['file_size'];
$folder_index = $rs['folder_index'];
$file_location = PHPDISK_ROOT.$settings['public_file_path'].'/'.$folder_index.'/'.$file_real_name;
}
if(!file_exists($file_location)){
alert('images/file_not_found.gif');
}
if($settings['public_max_flow_down']){
$max_flow_byte = get_byte_value($settings['public_max_flow_down']);
$down_flow_byte = get_byte_value($stats['public_down_flow_count']);
if($down_flow_byte >= $max_flow_byte){
alert('images/bandwidth_exceeded.gif');
}
}
$file_name = iconv('utf-8','gbk',$file_name);
header('Cache-control: max-age=2592000');
header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T',time()+2592000));
header('Content-disposition: attachment;filename="'.$file_name.'"');
if($file_mime){
header('Content-type: '.$file_mime);
}else{
header('Content-type: '.mime_type($file_extension));
}
header('Content-length: '.filesize($file_location));
$speed = 0;
$sleep = $speed ? floor(($chunk/($speed*1024))*1000000) : 0;
$sent = 0;
if(($fp = fopen($file_location,'rb')) === false) exit('Can not open file!');
do{
$buf = fread($fp,$chunk);
$sent += strlen($buf);
echo $buf;
flush();
usleep($sleep);
}while(!feof($fp) && !connection_aborted());
fclose($fp);
$db->query_unbuffered("update pd_publics set file_downs=file_downs+1,file_last_view='$timestamp' where file_id='$file_id' and file_key='$file_key'");
$public_down_flow_count = get_size(get_byte_value($stats['public_down_flow_count'])+$file_size);
$db->query("replace into pd_stats(vars,value) values('public_down_flow_count','$public_down_flow_count');");
write_cache('stats');
}else{
$rs = $db->fetch_one_array("select * from pd_files where file_id='$file_id' and file_key='$file_key'");
if($rs){
$pd_uid = $rs['userid'];
$file_real_name = $rs['file_real_name'];
$tmp_ext = $rs['file_extension'] ? '.'.$rs['file_extension'] : "";
$file_name = $rs['file_name'].$tmp_ext;
$file_extension = $rs['file_extension'];
$file_mime = $rs['file_mime'];
$file_size = $rs['file_size'];
$folder_index = $rs['folder_index'];
$file_location = PHPDISK_ROOT.$settings['file_path'].'/'.$pd_uid.'/'.$folder_index.'/'.$file_real_name;
}
if(!file_exists($file_location)){
alert('images/file_not_found.gif');
}
$rs = $db->fetch_one_array("select gid,down_flow_count,flow_reset_time from pd_users where userid='$pd_uid'");
$group_set = $group_settings[$rs['gid']];
if($group_set['max_flow_down']){
$max_flow_byte = get_byte_value($group_set['max_flow_down']);
$down_flow_byte = get_byte_value($rs['down_flow_count']);
if($down_flow_byte >= $max_flow_byte){
if($timestamp-$flow_reset_time >86400*30){
$db->query_unbuffered("update pd_users set down_flow_count=0 where userid='$pd_uid'");
}else{
$db->query_unbuffered("update pd_users set flow_reset_time='$timestamp' where userid='$pd_uid'");
alert('images/bandwidth_exceeded.gif');
}
}
}
$file_name = iconv('utf-8','gbk',$file_name);
header('Cache-control: max-age=2592000');
header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T',time()+2592000));
header('Content-disposition: attachment;filename="'.$file_name.'"');
if($file_mime){
header('Content-type: '.$file_mime);
}else{
header('Content-type: '.mime_type($file_extension));
}
header('Content-length: '.filesize($file_location));
$speed = get_byte_value($group_set['down_trans_rate']);
$sleep = $speed ? floor(($chunk/($speed*1024))*1000000) : 0;
$sent = 0;
if(($fp = fopen($file_location,'rb')) === false) exit('Can not open file!');
do{
$buf = fread($fp,$chunk);
$sent += strlen($buf);
echo $buf;
flush();
usleep($sleep);
}while(!feof($fp) && !connection_aborted());
fclose($fp);
$db->query_unbuffered("update pd_files set file_downs=file_downs+1,file_last_view='$timestamp' where file_id='$file_id' and file_key='$file_key'");
$rs = $db->fetch_one_array("select down_flow_count from pd_users where userid='$pd_uid'");
if($rs){
$down_flow_byte = get_byte_value($rs['down_flow_count']);
$down_flow_byte += $file_size;
$down_flow_count = get_size($down_flow_byte);
}
unset($rs);
$db->query_unbuffered("update pd_users set down_flow_count='$down_flow_count' where userid='$pd_uid'");
}
include PHPDISK_ROOT."./includes/footer.inc.php";
?>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -