求大神帮忙注释一下php代码,越详细越好
publicfunctiondownload(){$this->_layout='null';$file_name=ParamHolder::get('file_name...
public function download() {
$this->_layout = 'null';
$file_name =ParamHolder::get('file_name', '0');
if(MOD_REWRITE=='3'){
include(P_INC.'/custom.php');
$_path=strtolower(ParamHolder::get('_path', ''));
$arr = explode("-",$_path);
$dw_id = intval($arr[1]);
}else{
$dw_id =ParamHolder::get('dw_id', '0');
}
if (intval($dw_id) == 0) {
$this->assign('json',Toolkit::jsonERR(__('Invalid ID!')));
return '_error';
}
$curr_locale = trim(SessionHolder::get('_LOCALE'));
$user_role =trim(SessionHolder::get('user/s_role', '{guest}'));
try {
$now = time();
$o_dw = new Download();
if (!ACL::isRoleAdmin()){
$curr_dw =&$o_dw->find("`id`=? AND "
."((`pub_start_time`<? AND `pub_end_time`>=?) OR "
."(`pub_start_time`<? AND `pub_end_time`='-1') OR "
."(`pub_start_time`='-1' AND `pub_end_time`>=?) OR "
."(`pub_start_time`='-1' AND `pub_end_time`='-1')) AND "
."published='1' AND for_roles LIKE ? AND s_locale=?",
array($dw_id,$now, $now, $now, $now, '%'.$user_role.'%', $curr_locale));
} else {
$curr_dw =&$o_dw->find("`id`=? AND "
."((`pub_start_time`<? AND `pub_end_time`>=?) OR "
."(`pub_start_time`<? AND `pub_end_time`='-1') OR "
."(`pub_start_time`='-1'AND `pub_end_time`>=?) OR "
."(`pub_start_time`='-1' AND `pub_end_time`='-1')) AND "
."published='1' AND s_locale=?",
array($dw_id,$now, $now, $now, $now, $curr_locale));
}
if(sizeof($curr_dw) <=0) {
$this->assign('json', Toolkit::jsonERR(__('Invalid ID!')));
return '_error';
}
} catch (Exception $ex) {
$this->assign('json',Toolkit::jsonERR($ex->getMessage()));
return '_error';
}
if(!file_exists(ROOT.'/upload/file/'.$curr_dw->name)) {
$this->assign('json',Toolkit::jsonERR(__('File does not exist!')));
return '_error';
}
include_onceP_LIB."/download.php";
$o_filedownload = newfile_download();
$o_filedownload->downloadfile(ROOT.'/upload/file/'.$curr_dw->name);
//$this->file_download(ROOT.'/upload/file/'.$curr_dw->name);
} 展开
$this->_layout = 'null';
$file_name =ParamHolder::get('file_name', '0');
if(MOD_REWRITE=='3'){
include(P_INC.'/custom.php');
$_path=strtolower(ParamHolder::get('_path', ''));
$arr = explode("-",$_path);
$dw_id = intval($arr[1]);
}else{
$dw_id =ParamHolder::get('dw_id', '0');
}
if (intval($dw_id) == 0) {
$this->assign('json',Toolkit::jsonERR(__('Invalid ID!')));
return '_error';
}
$curr_locale = trim(SessionHolder::get('_LOCALE'));
$user_role =trim(SessionHolder::get('user/s_role', '{guest}'));
try {
$now = time();
$o_dw = new Download();
if (!ACL::isRoleAdmin()){
$curr_dw =&$o_dw->find("`id`=? AND "
."((`pub_start_time`<? AND `pub_end_time`>=?) OR "
."(`pub_start_time`<? AND `pub_end_time`='-1') OR "
."(`pub_start_time`='-1' AND `pub_end_time`>=?) OR "
."(`pub_start_time`='-1' AND `pub_end_time`='-1')) AND "
."published='1' AND for_roles LIKE ? AND s_locale=?",
array($dw_id,$now, $now, $now, $now, '%'.$user_role.'%', $curr_locale));
} else {
$curr_dw =&$o_dw->find("`id`=? AND "
."((`pub_start_time`<? AND `pub_end_time`>=?) OR "
."(`pub_start_time`<? AND `pub_end_time`='-1') OR "
."(`pub_start_time`='-1'AND `pub_end_time`>=?) OR "
."(`pub_start_time`='-1' AND `pub_end_time`='-1')) AND "
."published='1' AND s_locale=?",
array($dw_id,$now, $now, $now, $now, $curr_locale));
}
if(sizeof($curr_dw) <=0) {
$this->assign('json', Toolkit::jsonERR(__('Invalid ID!')));
return '_error';
}
} catch (Exception $ex) {
$this->assign('json',Toolkit::jsonERR($ex->getMessage()));
return '_error';
}
if(!file_exists(ROOT.'/upload/file/'.$curr_dw->name)) {
$this->assign('json',Toolkit::jsonERR(__('File does not exist!')));
return '_error';
}
include_onceP_LIB."/download.php";
$o_filedownload = newfile_download();
$o_filedownload->downloadfile(ROOT.'/upload/file/'.$curr_dw->name);
//$this->file_download(ROOT.'/upload/file/'.$curr_dw->name);
} 展开
1个回答
2016-05-10
展开全部
//定义一个public的成员函数download
public function download() {
$this->_layout = 'null'; //给成员变量赋值
$file_name =ParamHolder::get('file_name', '0'); //调用ParamHolder的静态方法get来获取filename,具体没有代码无法得知如何处理
if(MOD_REWRITE=='3'){ //判断MOD_REWRITE宏
include(P_INC.'/custom.php'); 包含custom.php文件
$_path=strtolower(ParamHolder::get('_path', '')); 同上获取_path参数并转换成小写
$arr = explode("-",$_path); //使用-吧$_path分割成数组
$dw_id = intval($arr[1]); //吧数组的第二个元素转换成int类型
}else{
$dw_id =ParamHolder::get('dw_id', '0'); //同上获取dw_id参数
}
if (intval($dw_id) == 0) { //转换dw_id为int类型然后判断是否等于0
$this->assign('json',Toolkit::jsonERR(__('Invalid ID!'))); //这个应该是用了什么框架的模板来输出json内容
return '_error';
}
$curr_locale = trim(SessionHolder::get('_LOCALE')); //获取SESSION中的_LOCALE值,并去除空格
$user_role =trim(SessionHolder::get('user/s_role', '{guest}')); //获取SESSION中的user/s_role,然后去除空格,默认为{guest}
try { //try 来捕获异常
$now = time(); //获取当前时间
$o_dw = new Download(); //新建一个Download类,没有具体代码无法知道内容
if (!ACL::isRoleAdmin()){ //根据命名来来猜测, 判断当前用户是否是Admin
$curr_dw =&$o_dw->find("`id`=? AND "
."((`pub_start_time`<? AND `pub_end_time`>=?) OR "
."(`pub_start_time`<? AND `pub_end_time`='-1') OR "
."(`pub_start_time`='-1' AND `pub_end_time`>=?) OR "
."(`pub_start_time`='-1' AND `pub_end_time`='-1')) AND "
."published='1' AND for_roles LIKE ? AND s_locale=?",
array($dw_id,$now, $now, $now, $now, '%'.$user_role.'%', $curr_locale)); //执行一个SQL查找语句 具体作用可能是查找dw_id是否存在
} else {
$curr_dw =&$o_dw->find("`id`=? AND "
."((`pub_start_time`<? AND `pub_end_time`>=?) OR "
."(`pub_start_time`<? AND `pub_end_time`='-1') OR "
."(`pub_start_time`='-1'AND `pub_end_time`>=?) OR "
."(`pub_start_time`='-1' AND `pub_end_time`='-1')) AND "
."published='1' AND s_locale=?",
array($dw_id,$now, $now, $now, $now, $curr_locale)); //同上
}
if(sizeof($curr_dw) <=0) { //判断$curr_dw的大小是否小于等于0
$this->assign('json', Toolkit::jsonERR(__('Invalid ID!'))); //使用模板来输出个json内容
return '_error';
}
} catch (Exception $ex) { //捕获异常
$this->assign('json',Toolkit::jsonERR($ex->getMessage())); //使用json来输出捕获的异常
return '_error';
}
if(!file_exists(ROOT.'/upload/file/'.$curr_dw->name)) { //判断从数据库中取到的信息的name拼接成一个路径判断是否存在
$this->assign('json',Toolkit::jsonERR(__('File does not exist!'))); //同上
return '_error';
}
include_once P_LIB."/download.php"; //包含download.php文件
$o_filedownload = newfile_download(); //无法得知newfile_download函数具体内容
$o_filedownload->downloadfile(ROOT.'/upload/file/'.$curr_dw->name)
; //上下文猜测可能是把表单传递过来的file移动到指定目录里。
//$this->file_download(ROOT.'/upload/file/'.$curr_dw->name);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询