You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
248 lines
7.6 KiB
248 lines
7.6 KiB
<?php
|
|
require("../../class/connect.php");
|
|
require("../../class/db_sql.php");
|
|
require("../../class/q_functions.php");
|
|
require("../../member/class/user.php");
|
|
require("../../data/dbcache/class.php");
|
|
require("../../data/dbcache/MemberLevel.php");
|
|
require("../class/DownSysFun.php");
|
|
eCheckCloseMods('down');//关闭模块
|
|
$link=db_connect();
|
|
$empire=new mysqlquery();
|
|
$editor=1;
|
|
$ecmsreurl=2;
|
|
//验证IP
|
|
eCheckAccessDoIp('downinfo');
|
|
$id=(int)$_GET['pid'];
|
|
$callback=$_GET['callback'];
|
|
$pathid=(int)$_GET['pathid'];
|
|
$classid=(int)$_GET['classid'];
|
|
$code=$_GET['code'];
|
|
if(!$classid||empty($class_r[$classid][tbname])||!$id)
|
|
{
|
|
echo"<script>alert('此信息不存在');window.close();</script>";
|
|
exit();
|
|
}
|
|
$mid=$class_r[$classid][modid];
|
|
$tbname=$class_r[$classid][tbname];
|
|
$query="select * from {$dbtbpre}ecms_".$tbname." where id='$id' limit 1";
|
|
$r=$empire->fetch1($query);
|
|
if(!$r['id']||$r['classid']!=$classid)
|
|
{
|
|
echo"<script>alert('此信息不存在');window.close();</script>";
|
|
exit();
|
|
}
|
|
//副表
|
|
$finfor=$empire->fetch1("select ".ReturnSqlFtextF($mid)." from {$dbtbpre}ecms_".$tbname."_data_".$r[stb]." where id='$r[id]' limit 1");
|
|
$r=array_merge($r,$finfor);
|
|
//区分下载地址
|
|
$path_r=explode("\r\n",$r[downpath]);
|
|
if(!$path_r[$pathid])
|
|
{
|
|
//echo"<script>alert('此信息不存在');window.close();</script>";
|
|
//exit();
|
|
}
|
|
$showdown_r=explode("::::::",$path_r[$pathid]);
|
|
//下载权限
|
|
$nockpass='';
|
|
$user=array();
|
|
$downgroup=$showdown_r[2];
|
|
if($downgroup)
|
|
{
|
|
$user=isloginc();
|
|
//取得会员资料
|
|
$u=$empire->fetch1("select ".eReturnSelectMemberF('*')." from ".eReturnMemberTable()." where ".egetmf('userid')."='$user[userid]' and ".egetmf('rnd')."='$user[rnd]' limit 1");
|
|
if(empty($u['userid']))
|
|
{
|
|
echo $callback.'({"status":0,"why":"请你登录","whyinfo":3});';
|
|
exit();
|
|
}
|
|
$nockpass=qReturnLoginPassNoCK($user['userid'],$user['username'],$user['rnd'],0);
|
|
//下载次数限制
|
|
if($level_r[$u['groupid']]['daydown'])
|
|
{
|
|
$setuserday=DoCheckMDownNum($user['userid'],$u['groupid'],2);
|
|
if($setuserday=='error')
|
|
{
|
|
echo $callback.'({"status":0,"why":"升级vip获取更多下载","whyinfo":3});';
|
|
exit();
|
|
}
|
|
}
|
|
if($downgroup>0)//会员组
|
|
{
|
|
if($level_r[$downgroup][level]>$level_r[$u['groupid']][level])
|
|
{
|
|
echo $callback.'({"status":0,"why":"开通vip获取更多下载","whyinfo":3});';
|
|
exit();
|
|
}
|
|
}
|
|
else//访问组
|
|
{
|
|
$vgroupid=0-$downgroup;
|
|
$ckvgresult=eMember_ReturnCheckViewGroup($u,$vgroupid);
|
|
if($ckvgresult<>'empire.cms')
|
|
{
|
|
exit();
|
|
}
|
|
}
|
|
|
|
//点数是否足够
|
|
$showdown_r[3]=intval($showdown_r[3]);
|
|
//if($showdown_r[3])
|
|
//{
|
|
//---------是否有历史记录
|
|
$bakr=$empire->fetch1("select id,truetime from {$dbtbpre}enewsdownrecord where id='$id' and classid='$classid' and userid='$user[userid]' and pathid='$pathid' and online=0 order by truetime desc limit 1");
|
|
if($bakr[id]&&(time()-$bakr[truetime]<=$public_r[redodown]*3600))
|
|
{}
|
|
else
|
|
{
|
|
//包月卡
|
|
if($u['userdate']-time()>0)
|
|
{
|
|
}
|
|
//点数
|
|
else
|
|
{
|
|
if($showdown_r[3]>$u['userfen'])
|
|
{
|
|
printerror("NotEnoughFen","history.go(-1)",1);
|
|
}
|
|
//去除点数
|
|
$usql=$empire->query("update ".eReturnMemberTable()." set ".egetmf('userfen')."=".egetmf('userfen')."-".$showdown_r[3]." where ".egetmf('userid')."='$user[userid]'");
|
|
}
|
|
//备份下载记录
|
|
$utfusername=$u['username'];
|
|
BakDown($classid,$id,$pathid,$user[userid],$utfusername,$r[title],$showdown_r[3],0);
|
|
}
|
|
|
|
//}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//变量
|
|
$thisdownname=$showdown_r[0]; //当前下载地址名称
|
|
$classname=$class_r[$r[classid]]['classname']; //栏目名
|
|
$bclassid=$class_r[$r[classid]]['bclassid']; //父栏目ID
|
|
$bclassname=$class_r[$bclassid]['classname']; //父栏目名
|
|
$titleurl=sys_ReturnBqTitleLink($r); //信息链接
|
|
$newstime=date('Y-m-d H:i:s',$r['newstime']);
|
|
$titlepic=$r['titlepic']?$r['titlepic']:$public_r[newsurl]."e/data/images/notimg.gif";
|
|
$ip=egetip();
|
|
$pass=md5(md5($classid."-!ecms!".$id."-!ecms!".$pathid).ReturnDownSysCheckIp()."wm_chief".$public_r[downpass].$user[userid]); //验证码
|
|
$url="/e/DownSys/doaction.php?enews=DownSoft&classid=$classid&id=$id&pathid=$pathid&pass=".$pass."&p=".$user[userid].":::".$user[rnd].":::".$nockpass; //下载地址
|
|
$p=$user[userid].":::".$user[rnd].":::".$nockpass;
|
|
$trueurl=ReturnDSofturl($showdown_r[1],$showdown_r[4],'../../',1); //真实文件地址
|
|
$fen=$showdown_r[3]; //下载点数
|
|
$downuser=$downgroup?$level_r[$downgroup][groupname]:'游客'; //下载等级
|
|
|
|
$ok=check_remote_file_exists($public_r['add_file'].$trueurl); // 返回1,说明存在。
|
|
if (!$ok){
|
|
$trueurl='';
|
|
}
|
|
|
|
|
|
|
|
if (!$trueurl){
|
|
$cid = basename($r['cid']);
|
|
$cid=str_replace('.html','',$cid);
|
|
header("Content-Type:text/html;charset=utf-8");
|
|
$ch =curl_init();
|
|
curl_setopt($ch,CURLOPT_URL,'http://www.tukuppt.com/index/down?code='.$code.'&pid='.$cid);
|
|
$header = array();
|
|
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
|
|
curl_setopt($ch,CURLOPT_HEADER,true);
|
|
curl_setopt($ch,CURLOPT_HTTPHEADER,$header);
|
|
curl_setopt($ch,CURLOPT_COOKIE,$public_r['add_cookie']);
|
|
$content = curl_exec($ch);
|
|
preg_match('|"whyinfo":(.*?)}|i',$content,$codes);
|
|
if ($codes[1]==5){
|
|
echo $callback.'({"status":0,"why":"请输入验证码","whyinfo":5});';
|
|
exit();
|
|
}
|
|
if ($codes[1]==7){
|
|
echo $callback.'({"status":0,"why":"验证码错误","whyinfo":7});';
|
|
exit();
|
|
}
|
|
preg_match('|downurl":"(.*?)"|i',$content,$match);
|
|
$url =$match[1];
|
|
$url=str_replace('\/','/',$url);
|
|
$save_dir = "../../../d/file/down/".date('Y',time())."/".date('m',time())."/".date('d',time());
|
|
$filename = basename($url);
|
|
$newurl=$save_dir.'/'.$filename;
|
|
$trueurl=str_replace('../../..','',$newurl);
|
|
$res = getFile($url, $save_dir, $filename, 1);
|
|
$downpath="下载地址一::::::$trueurl::::::2::::::0";
|
|
$empire->query("update {$dbtbpre}ecms_".$tbname." set downpath='$downpath' where id='$id' limit 1");
|
|
}
|
|
$empire->query("update {$dbtbpre}ecms_".$tbname." set totaldown=totaldown+1 where id='$id' limit 1");
|
|
echo $callback.'({"status":1,"downurl":"'.$public_r['add_file'].$trueurl.'"});';
|
|
exit();
|
|
|
|
|
|
db_close();
|
|
$empire=null;
|
|
|
|
|
|
|
|
function getFile($url, $save_dir = '', $filename = '', $type = 0) {
|
|
if (trim($url) == '') {
|
|
return false;
|
|
}
|
|
if (trim($save_dir) == '') {
|
|
$save_dir = './';
|
|
}
|
|
if (0 !== strrpos($save_dir, '/')) {
|
|
$save_dir.= '/';
|
|
}
|
|
//创建保存目录
|
|
if (!file_exists($save_dir) && !mkdir($save_dir, 0777, true)) {
|
|
return false;
|
|
}
|
|
//获取远程文件所采用的方法
|
|
if ($type) {
|
|
$ch = curl_init();
|
|
$timeout = 5;
|
|
curl_setopt($ch, CURLOPT_URL, $url);
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
|
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
|
|
$content = curl_exec($ch);
|
|
curl_close($ch);
|
|
} else {
|
|
ob_start();
|
|
readfile($url);
|
|
$content = ob_get_contents();
|
|
ob_end_clean();
|
|
}
|
|
$size = strlen($content);
|
|
//文件大小
|
|
$fp2 = @fopen($save_dir . $filename, 'a');
|
|
fwrite($fp2, $content);
|
|
fclose($fp2);
|
|
unset($content, $url);
|
|
return array(
|
|
'file_name' => $filename,
|
|
'save_path' => $save_dir . $filename
|
|
);
|
|
}
|
|
function check_remote_file_exists($url) {
|
|
$curl = curl_init($url); // 不取回数据
|
|
curl_setopt($curl, CURLOPT_NOBODY, true);
|
|
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'GET'); // 发送请求
|
|
$result = curl_exec($curl);
|
|
$found = false; // 如果请求没有发送失败
|
|
if ($result !== false) {
|
|
|
|
/** 再检查http响应码是否为200 */
|
|
$statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
|
if ($statusCode == 200) {
|
|
$found = true;
|
|
}
|
|
}
|
|
curl_close($curl);
|
|
|
|
return $found;
|
|
}
|
|
?>
|