uploadAction.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. class uploadClassAction extends Action{
  3. /**
  4. * 上传文件页面
  5. */
  6. public function defaultAction()
  7. {
  8. $callback = $this->get('callback');
  9. $callbacka = explode('|', $callback);
  10. $params['callback'] = $callbacka[0];
  11. $params['changeback'] = arrvalue($callbacka,1);
  12. $params['maxup'] = $this->get('maxup','0');
  13. $params['thumbnail'] = $this->get('thumbnail');
  14. $params['maxwidth'] = $this->get('maxwidth','0');
  15. $params['showid'] = $this->get('showid');
  16. $params['upkey'] = $this->get('upkey');
  17. $params['uptype'] = $this->get('uptype','*');
  18. $params['thumbtype'] = $this->get('thumbtype','0');
  19. $params['maxsize'] = (int)$this->get('maxsize', c('upfile')->getmaxzhao());
  20. $urlparams = '{}';
  21. $urlcan = $this->get('urlparams');//格式:a=b,c=d
  22. if(!isempt($urlcan)){
  23. $cans1 = explode(',', $urlcan);
  24. $urlparams = array();
  25. foreach($cans1 as $cans2){
  26. $cans3 = explode(':', $cans2);
  27. $urlparams[$cans3[0]]=$cans3[1];
  28. }
  29. $urlparams = json_encode($urlparams);
  30. }
  31. $params['urlparams'] = $urlparams;
  32. $this->title = $this->get('title','文件上传');
  33. $this->assign('params', $params);
  34. $this->assign('callback', $params['callback']);
  35. }
  36. public function upfileAjax()
  37. {
  38. if(!$_FILES)exit('sorry!');
  39. $upimg = c('upfile');
  40. $maxsize= (int)$this->get('maxsize', 5);
  41. $uptype = $this->get('uptype', '*');
  42. $thumbnail = $this->get('thumbnail');
  43. $upimg->initupfile($uptype, ''.UPDIR.'|'.date('Y-m').'', $maxsize);
  44. $upses = $upimg->up('file');
  45. $arr = c('down')->uploadback($upses, $thumbnail, false);
  46. $this->returnjson($arr);
  47. }
  48. /**
  49. * 获取文件
  50. */
  51. public function getfileAjax()
  52. {
  53. $mtype = $this->request('mtype');
  54. $mid = (int)$this->request('mid');
  55. $rows = m('file')->getfiles($mtype, $mid);
  56. echo json_encode($rows);
  57. }
  58. /**
  59. * 删除文件(可能有引入的文件)
  60. */
  61. public function delfileAjax()
  62. {
  63. $id = (int)$this->request('id','0');
  64. $mid = (int)$this->get('mid','0');
  65. $num = $this->get('num');
  66. $bo = true;
  67. if($num && $mid>0){
  68. $where = '`fileid`='.$id.' and `type`=3 and `ip`=\''.$num.'|'.$mid.'\'';
  69. $srs = m('files')->getall($where);
  70. if($srs){
  71. $bo = false;
  72. m('files')->delete($srs[0]['id']);
  73. }
  74. }
  75. if($bo)m('file')->delfile($id);
  76. }
  77. public function showAction()
  78. {
  79. $id = (int)$this->get('id','0');
  80. $this->display = false;
  81. m('file')->show($id);
  82. }
  83. /**
  84. * 编辑器上传文件
  85. */
  86. public function upimgAction()
  87. {
  88. $this->display = false;
  89. $upfile = c('upfile');
  90. $upfile->initupfile('jpg|png|gif|jpeg',''.UPDIR.'|'.date('Y-m').'', 5);
  91. $upses = $upfile->up('imgFile');
  92. if(is_array($upses)){
  93. $url = $upses['allfilename'];
  94. $url = str_replace('../' , '', $url);
  95. $arr = array('error' => 0, 'url' => $url);
  96. }else{
  97. $arr = array('error' => 1, 'message' => $upses);
  98. }
  99. $this->returnjson($arr);
  100. }
  101. }
粤ICP备19079148号