AttachmentAction.class.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. <?php
  2. /**
  3. *
  4. * Attachment(附件管理)
  5. *
  6. */
  7. if(!defined("Ainaphp")) exit("Access Denied");
  8. class AttachmentAction extends Action {
  9. protected $lang,$dao,$Config,$sysConfig,$isadmin=0,$userid=0,$groupid=0;
  10. function _initialize()
  11. {
  12. $this->isadmin= $_REQUEST['isadmin'] ? $_REQUEST['isadmin'] : 0;
  13. $this->sysConfig = F('sys.config');
  14. if(APP_LANG){
  15. $this->Lang = F('Lang');
  16. $this->assign('Lang',$this->Lang);
  17. if($_GET['l']){
  18. if(!$this->Lang[$_GET['l']]['status'])$this->error ( L ( 'NO_LANG' ) );
  19. $lang=$_GET['l'];
  20. }else{
  21. $lang=$this->sysConfig['DEFAULT_LANG'];
  22. }
  23. define('LANG_NAME', $lang);
  24. define('LANG_ID', $this->Lang[$lang]['id']);
  25. $this->Config = F('Config_'.LANG_NAME);
  26. }else{
  27. $this->Config = F('Config');
  28. }
  29. if($_POST['PHPSESSID'] && $_POST['swf_auth_key'] && $_POST['userid']){
  30. if($_POST['swf_auth_key']==sysmd5($_POST['PHPSESSID'].$_POST['userid'],$this->sysConfig['ADMIN_ACCESS'])){
  31. $this->userid = $_POST['userid'];
  32. if(APP_LANG) $this->Config = F('Config_'.$_POST['lang']);
  33. }
  34. }
  35. if(!$this->userid){
  36. if($this->isadmin){
  37. import('@.Action.Adminbase');
  38. $Adminbase=new AdminbaseAction();
  39. $Adminbase->_initialize();
  40. $this->userid= $_SESSION[C('USER_AUTH_KEY')];
  41. $this->groupid= $_SESSION['groupid'];
  42. }else{
  43. C('ADMIN_ACCESS',$this->sysConfig['ADMIN_ACCESS']);
  44. if($_COOKIE['YP_auth']){
  45. if(!strstr($_SERVER['HTTP_USER_AGENT'],'Flash'))cookie('YP_cookie',$_SERVER['HTTP_USER_AGENT']);
  46. $HTTP_USER_AGENT = strstr($_SERVER['HTTP_USER_AGENT'],'Flash') ? $_COOKIE['YP_cookie'] : $_SERVER['HTTP_USER_AGENT'];
  47. $yourphp_auth_key = sysmd5($this->sysConfig['ADMIN_ACCESS'].$HTTP_USER_AGENT);
  48. list($userid, $groupid ,$password) = explode("-", authcode($_COOKIE['YP_auth'], 'DECODE', $yourphp_auth_key));
  49. $this->userid = $userid;
  50. $this->groupid = $groupid;
  51. }
  52. if(!$this->userid){
  53. $this->assign('jumpUrl',U('User/Login/index'));
  54. $this->error(L('no_login'));
  55. }
  56. }
  57. }
  58. $this->assign($this->Config);
  59. $this->dao=M('Attachment');
  60. }
  61. public function index(){
  62. $auth = str_replace(' ','+',$_REQUEST['auth']) ;
  63. $postd=array('isadmin','more','isthumb','file_limit','file_types','file_size','moduleid');
  64. foreach((array)$_REQUEST as $key=>$res){
  65. if(in_array($key,$postd))$postdata[$key]=$res;
  66. }
  67. $upsetup = implode('-',$postdata);
  68. $yourphp_auth_key = sysmd5(C('ADMIN_ACCESS').$_SERVER['HTTP_USER_AGENT']);
  69. $enupsetup = authcode($auth, 'DECODE', $yourphp_auth_key);
  70. if(!$enupsetup || $upsetup!=$enupsetup) $this->error (L('do_empty'));
  71. $sessid = time();
  72. $count = $this->dao->where('status=0 and userid ='.$this->userid)->count();
  73. $this->assign('no_use_files',$count);
  74. $this->assign('small_upfile_limit',$_REQUEST['file_limit'] - $count);
  75. $types = '*.'.str_replace(",",";*.",$_REQUEST['file_types']); ;
  76. $this->assign('moduleid',$_REQUEST['moduleid']);
  77. $this->assign('file_size',$_REQUEST['file_size']);
  78. $this->assign('file_limit',$_REQUEST['file_limit']);
  79. $this->assign('file_types',$types);
  80. $this->assign('isthumb',$_REQUEST['isthumb']);
  81. $this->assign('isadmin',$this->isadmin);
  82. $this->assign('sessid',$sessid);
  83. $this->assign('lang',LANG_NAME);
  84. $this->assign('userid',$this->userid);
  85. $swf_auth_key = sysmd5($sessid.$this->userid);
  86. $this->assign('swf_auth_key',$swf_auth_key);
  87. $this->assign('more',$_GET['more']);
  88. $this->display();
  89. }
  90. public function upload(){
  91. //if($_POST['swf_auth_key']!= sysmd5($_POST['PHPSESSID'].$this->userid)) $this->ajaxReturn(0,'1-'.$_POST['PHPSESSID'],0);
  92. import("@.ORG.UploadFile");
  93. $upload = new UploadFile();
  94. //$upload->supportMulti = false;
  95. //设置上传文件大小
  96. $upload->maxSize = $this->Config['attach_maxsize'];
  97. $upload->autoSub = true;
  98. $upload->subType = 'date';
  99. $upload->dateFormat = 'Ym';
  100. //设置上传文件类型
  101. $upload->allowExts = explode(',', $this->Config['attach_allowext']);
  102. //设置附件上传目录
  103. $upload->savePath = UPLOAD_PATH;
  104. //设置上传文件规则
  105. $upload->saveRule = uniqid;
  106. //删除原图
  107. $upload->thumbRemoveOrigin = true;
  108. if (!$upload->upload()) {
  109. $this->ajaxReturn(0,$upload->getErrorMsg(),0);
  110. } else {
  111. //取得成功上传的文件信息
  112. $uploadList = $upload->getUploadFileInfo();
  113. if($_REQUEST['addwater']){ //$this->Config['watermark_enable'] $_REQUEST['addwater']
  114. import("@.ORG.Image");
  115. Image::watermark($uploadList[0]['savepath'].$uploadList[0]['savename'],'',$this->Config);
  116. }
  117. $imagearr = explode(',', 'jpg,gif,png,jpeg,bmp,ttf,tif');
  118. $data=array();
  119. $model = M('Attachment');
  120. //保存当前数据对象
  121. $data['moduleid'] = $_REQUEST['moduleid'];
  122. $data['catid'] = 0;
  123. $data['userid'] = $_REQUEST['userid'];
  124. $data['filename'] = $uploadList[0]['name'];
  125. $data['filepath'] = __ROOT__.substr($uploadList[0]['savepath'].strtolower($uploadList[0]['savename']),1);
  126. $data['filesize'] = $uploadList[0]['size'];
  127. $data['fileext'] = strtolower($uploadList[0]['extension']);
  128. $data['isimage'] = in_array($data['fileext'],$imagearr) ? 1 : 0;
  129. $data['isthumb'] = intval($_REQUEST['isthumb']);
  130. $data['createtime'] = time();
  131. $data['uploadip'] = get_client_ip();
  132. $aid = $model->add($data);
  133. $returndata['aid'] = $aid;
  134. $returndata['filepath'] = $data['filepath'];
  135. $returndata['fileext'] = $data['fileext'];
  136. $returndata['isimage'] = $data['isimage'];
  137. $returndata['filename'] = $data['filename'];
  138. $returndata['filesize'] = $data['filesize'];
  139. $this->ajaxReturn($returndata,L('upload_ok'), '1');
  140. }
  141. }
  142. public function filelist(){
  143. $where= $_REQUEST['typeid'] ? " status=1 " : " status=0 ";
  144. $where .=" and userid = ".$this->userid ;
  145. import ( '@.ORG.Page' );
  146. $count = $this->dao->where($where)->count();
  147. $page=new Page($count,12);
  148. $imagearr = explode(',', 'jpg,gif,png,jpeg,bmp,ttf,tif');
  149. $page->urlrule = 'javascript:ajaxload('.$_REQUEST['typeid'].',{$page},\''.$_REQUEST['inputid'].'\','.$this->isadmin.');';
  150. $show = $page->show();
  151. $this->assign("page",$show);
  152. $list=$this->dao->order('aid desc')->where($where)
  153. ->limit($page->firstRow.','.$page->listRows)->select();
  154. foreach((array)$list as $key=>$r){
  155. $list[$key]['thumb']=in_array($r['fileext'],$imagearr) ? $r['filepath'] : __ROOT__.'/Public/Images/ext/'.$r['fileext'].'.png';
  156. }
  157. $this->assign('list',$list);
  158. $this->display();
  159. }
  160. function delfile($aid){
  161. if(empty($aid)){
  162. $aid=$_REQUEST['aid'];
  163. }
  164. $r = delattach(array('aid'=>$aid,'userid'=>$this->userid));
  165. if($r){
  166. $this->success ( L ( 'delete_ok' ) );
  167. }else{
  168. $this->error ( L ( 'delete_error' ) );
  169. }
  170. }
  171. function cleanfile(){
  172. $r = delattach(array('status'=>0,'userid'=>$this->userid));
  173. if($r){
  174. $this->success ( L ( 'delete_ok' ) );
  175. }else{
  176. $this->error ( L ( 'delete_error' ) );
  177. }
  178. }
  179. }
  180. ?>