/source/class/class_forumupload.php

https://github.com/sichen/hrmmdiscuz · PHP · 125 lines · 101 code · 18 blank · 6 comment · 35 complexity · e89da48403195419e5771bc09503f979 MD5 · raw file

  1. <?php
  2. /**
  3. * [Discuz!] (C)2001-2099 Comsenz Inc.
  4. * This is NOT a freeware, use is subject to license terms
  5. *
  6. * $Id: class_forumupload.php 19297 2010-12-27 05:55:47Z monkey $
  7. */
  8. class forum_upload {
  9. var $uid;
  10. var $aid;
  11. var $simple;
  12. var $statusid;
  13. var $attach;
  14. var $error_sizelimit;
  15. function forum_upload() {
  16. global $_G;
  17. $_G['uid'] = $this->uid = intval($_G['gp_uid']);
  18. $swfhash = md5(substr(md5($_G['config']['security']['authkey']), 8).$this->uid);
  19. $this->aid = 0;
  20. $this->simple = !empty($_G['gp_simple']) ? $_G['gp_simple'] : 0;
  21. if($_G['gp_hash'] != $swfhash) {
  22. $this->uploadmsg(10);
  23. }
  24. $_G['groupid'] = intval(DB::result_first("SELECT groupid FROM ".DB::table('common_member')." WHERE uid='".$this->uid."'"));
  25. loadcache('usergroup_'.$_G['groupid']);
  26. $_G['group'] = $_G['cache']['usergroup_'.$_G['groupid']];
  27. require_once libfile('class/upload');
  28. $upload = new discuz_upload();
  29. $upload->init($_FILES['Filedata'], 'forum');
  30. $this->attach = &$upload->attach;
  31. if($upload->error()) {
  32. $this->uploadmsg(2);
  33. }
  34. $allowupload = !$_G['group']['maxattachnum'] || $_G['group']['maxattachnum'] && $_G['group']['maxattachnum'] > getuserprofile('todayattachs');;
  35. if(!$allowupload) {
  36. $this->uploadmsg(6);
  37. }
  38. if($_G['group']['attachextensions'] && (!preg_match("/(^|\s|,)".preg_quote($upload->attach['ext'], '/')."($|\s|,)/i", $_G['group']['attachextensions']) || !$upload->attach['ext'])) {
  39. $this->uploadmsg(1);
  40. }
  41. if(empty($upload->attach['size'])) {
  42. $this->uploadmsg(2);
  43. }
  44. if($_G['group']['maxattachsize'] && $upload->attach['size'] > $_G['group']['maxattachsize']) {
  45. $this->error_sizelimit = $_G['group']['maxattachsize'];
  46. $this->uploadmsg(3);
  47. }
  48. if($type = DB::fetch_first("SELECT maxsize FROM ".DB::table('forum_attachtype')." WHERE extension='".addslashes($upload->attach['ext'])."'")) {
  49. if($type['maxsize'] == 0) {
  50. $this->error_sizelimit = 'ban';
  51. $this->uploadmsg(4);
  52. } elseif($upload->attach['size'] > $type['maxsize']) {
  53. $this->error_sizelimit = $type['maxsize'];
  54. $this->uploadmsg(5);
  55. }
  56. }
  57. if($upload->attach['size'] && $_G['group']['maxsizeperday']) {
  58. $todaysize = getuserprofile('todayattachsize') + $upload->attach['size'];
  59. if($todaysize >= $_G['group']['maxsizeperday']) {
  60. $this->error_sizelimit = 'perday|'.$_G['group']['maxsizeperday'];
  61. $this->uploadmsg(11);
  62. }
  63. }
  64. updatemembercount($_G['uid'], array('todayattachs' => 1, 'todayattachsize' => $upload->attach['size']));
  65. $upload->save();
  66. if($upload->error() == -103) {
  67. $this->uploadmsg(8);
  68. } elseif($upload->error()) {
  69. $this->uploadmsg(9);
  70. }
  71. $thumb = $remote = $width = 0;
  72. if($_G['gp_type'] == 'image' && !$upload->attach['isimage']) {
  73. $this->uploadmsg(7);
  74. }
  75. if($upload->attach['isimage']) {
  76. if($_G['setting']['thumbstatus']) {
  77. require_once libfile('class/image');
  78. $image = new image;
  79. $thumb = $image->Thumb($upload->attach['target'], '', $_G['setting']['thumbwidth'], $_G['setting']['thumbheight'], $_G['setting']['thumbstatus'], $_G['setting']['thumbsource']) ? 1 : 0;
  80. $width = $image->imginfo['width'];
  81. }
  82. if($_G['setting']['thumbsource'] || !$_G['setting']['thumbstatus']) {
  83. list($width) = @getimagesize($upload->attach['target']);
  84. }
  85. }
  86. if($_G['gp_type'] != 'image' && $upload->attach['isimage']) {
  87. $upload->attach['isimage'] = -1;
  88. }
  89. $this->aid = $aid = getattachnewaid($this->uid);
  90. DB::query("INSERT INTO ".DB::table('forum_attachment_unused')." (aid, dateline, filename, filesize, attachment, isimage, uid, thumb, remote, width)
  91. VALUES ('$aid', '$_G[timestamp]', '".$upload->attach['name']."', '".$upload->attach['size']."', '".$upload->attach['attachment']."', '".$upload->attach['isimage']."', '".$this->uid."', '$thumb', '$remote', '$width')");
  92. $this->uploadmsg(0);
  93. }
  94. function uploadmsg($statusid) {
  95. global $_G;
  96. $this->error_sizelimit = !empty($this->error_sizelimit) ? $this->error_sizelimit : 0;
  97. if($this->simple == 1) {
  98. echo 'DISCUZUPLOAD|'.$statusid.'|'.$this->aid.'|'.$this->attach['isimage'].'|'.$this->error_sizelimit;
  99. } elseif($this->simple == 2) {
  100. echo 'DISCUZUPLOAD|'.($_G['gp_type'] == 'image' ? '1' : '0').'|'.$statusid.'|'.$this->aid.'|'.$this->attach['isimage'].'|'.$this->attach['attachment'].'|'.$this->attach['name'].'|'.$this->error_sizelimit;
  101. } else {
  102. echo $statusid ? 'error' : $this->aid;
  103. }
  104. exit;
  105. }
  106. }
  107. ?>