⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 viewfile.php

📁 创建虚拟磁盘。用户可以创建磁盘
💻 PHP
字号:
<?php 
##
#	Project: PHPDisk
#	This is NOT a freeware, use is subject to license terms.
#
#	Site: http://www.phpdisk.com
#
#	$Id: viewfile.php 269 2009-03-11 08:50:36Z along $
#
#	Copyright (C) 2008-2009 PHPDisk Team. All Rights Reserved.
#
##

error_reporting(0);
$chunk = 16384;

@set_time_limit(0);
@ignore_user_abort(true);
@set_magic_quotes_runtime(0);

define('PHPDISK_ROOT',dirname(__FILE__),'/');
define('IN_PHPDISK',TRUE);
$timestamp = time();

require_once PHPDISK_ROOT.'./system/configs.inc.php';
require_once PHPDISK_ROOT.'./system/settings.inc.php';
require_once PHPDISK_ROOT.'./system/stats.inc.php';
require_once PHPDISK_ROOT.'./system/group_settings.inc.php';
require_once PHPDISK_ROOT.'./includes/mysql.class.php';
require_once PHPDISK_ROOT.'./includes/global.func.php';

$db = new cls_mysql;
$db->connect($configs['dbhost'],$configs['dbuser'],$configs['dbpasswd'],$configs['dbname'],$configs['pconnect']);
unset($configs['dbhost'],$configs['dbuser'],$configs['dbpasswd'],$configs['pconnect']);

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_view']){
		$max_flow_byte = get_byte_value($settings['public_max_flow_view']);
		$view_flow_byte = get_byte_value($stats['public_view_flow_count']);
		if($view_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: inline;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_views=file_views+1 ,file_last_view='$timestamp' where file_id='$file_id' and file_key='$file_key'");
	$public_view_flow_count = get_size(get_byte_value($stats['public_view_flow_count'])+$file_size);
	$db->query("replace into pd_stats(vars,value) values('public_view_flow_count','$public_view_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,view_flow_count,flow_reset_time from pd_users where userid='$pd_uid'");
	$group_set = $group_settings[$rs['gid']];
	if($group_set['max_flow_view']){
		$max_flow_byte = get_byte_value($group_set['max_flow_view']);
		$view_flow_byte = get_byte_value($rs['view_flow_count']);
		if($view_flow_byte >= $max_flow_byte){
			if($timestamp-$flow_reset_time >86400*30){
				$db->query_unbuffered("update pd_users set view_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: inline;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['view_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_views=file_views+1 ,file_last_view='$timestamp' where file_id='$file_id' and file_key='$file_key'");
	$rs = $db->fetch_one_array("select view_flow_count from pd_users where userid='$pd_uid'");
	if($rs){
		$view_flow_byte = get_byte_value($rs['view_flow_count']);
		$view_flow_byte += $file_size;
		$view_flow_count = get_size($view_flow_byte);
	}
	unset($rs);
	$db->query_unbuffered("update pd_users set view_flow_count='$view_flow_count' where userid='$pd_uid'");

}
include PHPDISK_ROOT."./includes/footer.inc.php";

?>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -