| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- <?php
- class uploadClassAction extends Action{
-
- /**
- * 上传文件页面
- */
- public function defaultAction()
- {
- $callback = $this->get('callback');
- $callbacka = explode('|', $callback);
-
- $params['callback'] = $callbacka[0];
- $params['changeback'] = arrvalue($callbacka,1);
- $params['maxup'] = $this->get('maxup','0');
- $params['thumbnail'] = $this->get('thumbnail');
- $params['maxwidth'] = $this->get('maxwidth','0');
- $params['showid'] = $this->get('showid');
- $params['upkey'] = $this->get('upkey');
- $params['uptype'] = $this->get('uptype','*');
- $params['thumbtype'] = $this->get('thumbtype','0');
- $params['maxsize'] = (int)$this->get('maxsize', c('upfile')->getmaxzhao());
-
- $urlparams = '{}';
- $urlcan = $this->get('urlparams');//格式:a=b,c=d
- if(!isempt($urlcan)){
- $cans1 = explode(',', $urlcan);
- $urlparams = array();
- foreach($cans1 as $cans2){
- $cans3 = explode(':', $cans2);
- $urlparams[$cans3[0]]=$cans3[1];
- }
- $urlparams = json_encode($urlparams);
- }
- $params['urlparams'] = $urlparams;
-
- $this->title = $this->get('title','文件上传');
- $this->assign('params', $params);
- $this->assign('callback', $params['callback']);
- }
-
- public function upfileAjax()
- {
- if(!$_FILES)exit('sorry!');
- $upimg = c('upfile');
- $maxsize= (int)$this->get('maxsize', 5);
- $uptype = $this->get('uptype', '*');
- $thumbnail = $this->get('thumbnail');
- $upimg->initupfile($uptype, ''.UPDIR.'|'.date('Y-m').'', $maxsize);
- $upses = $upimg->up('file');
- $arr = c('down')->uploadback($upses, $thumbnail, false);
- $this->returnjson($arr);
- }
-
-
-
- /**
- * 获取文件
- */
- public function getfileAjax()
- {
- $mtype = $this->request('mtype');
- $mid = (int)$this->request('mid');
- $rows = m('file')->getfiles($mtype, $mid);
- echo json_encode($rows);
- }
-
- /**
- * 删除文件(可能有引入的文件)
- */
- public function delfileAjax()
- {
- $id = (int)$this->request('id','0');
- $mid = (int)$this->get('mid','0');
- $num = $this->get('num');
- $bo = true;
- if($num && $mid>0){
- $where = '`fileid`='.$id.' and `type`=3 and `ip`=\''.$num.'|'.$mid.'\'';
- $srs = m('files')->getall($where);
- if($srs){
- $bo = false;
- m('files')->delete($srs[0]['id']);
- }
- }
- if($bo)m('file')->delfile($id);
- }
-
- public function showAction()
- {
- $id = (int)$this->get('id','0');
- $this->display = false;
- m('file')->show($id);
- }
-
- /**
- * 编辑器上传文件
- */
- public function upimgAction()
- {
- $this->display = false;
- $upfile = c('upfile');
- $upfile->initupfile('jpg|png|gif|jpeg',''.UPDIR.'|'.date('Y-m').'', 5);
- $upses = $upfile->up('imgFile');
- if(is_array($upses)){
- $url = $upses['allfilename'];
- $url = str_replace('../' , '', $url);
- $arr = array('error' => 0, 'url' => $url);
- }else{
- $arr = array('error' => 1, 'message' => $upses);
- }
- $this->returnjson($arr);
- }
- }
|