forum_upload.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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: forum_upload.php 32858 2013-03-15 03:36:22Z zhangjie $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class forum_upload {
  12. var $uid;
  13. var $aid;
  14. var $simple;
  15. var $statusid;
  16. var $attach;
  17. var $error_sizelimit;
  18. var $getaid;
  19. function forum_upload($getaid = 0) {
  20. global $_G;
  21. $_G['uid'] = $this->uid = intval($_GET['uid']);
  22. $swfhash = md5(substr(md5($_G['config']['security']['authkey']), 8).$this->uid);
  23. $this->aid = 0;
  24. $this->getaid = $getaid;
  25. $this->simple = !empty($_GET['simple']) ? $_GET['simple'] : 0;
  26. if($_GET['hash'] != $swfhash) {
  27. return $this->uploadmsg(10);
  28. }
  29. $upload = new discuz_upload();
  30. $upload->init($_FILES['Filedata'], 'forum');
  31. $this->attach = &$upload->attach;
  32. if($upload->error()) {
  33. return $this->uploadmsg(2);
  34. }
  35. $allowupload = !$_G['group']['maxattachnum'] || $_G['group']['maxattachnum'] && $_G['group']['maxattachnum'] > getuserprofile('todayattachs');;
  36. if(!$allowupload) {
  37. return $this->uploadmsg(6);
  38. }
  39. if($_G['group']['attachextensions'] && (!preg_match("/(^|\s|,)".preg_quote($upload->attach['ext'], '/')."($|\s|,)/i", $_G['group']['attachextensions']) || !$upload->attach['ext'])) {
  40. return $this->uploadmsg(1);
  41. }
  42. if(empty($upload->attach['size'])) {
  43. return $this->uploadmsg(2);
  44. }
  45. if($_G['group']['maxattachsize'] && $upload->attach['size'] > $_G['group']['maxattachsize']) {
  46. $this->error_sizelimit = $_G['group']['maxattachsize'];
  47. return $this->uploadmsg(3);
  48. }
  49. loadcache('attachtype');
  50. if($_G['fid'] && isset($_G['cache']['attachtype'][$_G['fid']][$upload->attach['ext']])) {
  51. $maxsize = $_G['cache']['attachtype'][$_G['fid']][$upload->attach['ext']];
  52. } elseif(isset($_G['cache']['attachtype'][0][$upload->attach['ext']])) {
  53. $maxsize = $_G['cache']['attachtype'][0][$upload->attach['ext']];
  54. }
  55. if(isset($maxsize)) {
  56. if(!$maxsize) {
  57. $this->error_sizelimit = 'ban';
  58. return $this->uploadmsg(4);
  59. } elseif($upload->attach['size'] > $maxsize) {
  60. $this->error_sizelimit = $maxsize;
  61. return $this->uploadmsg(5);
  62. }
  63. }
  64. if($upload->attach['size'] && $_G['group']['maxsizeperday']) {
  65. $todaysize = getuserprofile('todayattachsize') + $upload->attach['size'];
  66. if($todaysize >= $_G['group']['maxsizeperday']) {
  67. $this->error_sizelimit = 'perday|'.$_G['group']['maxsizeperday'];
  68. return $this->uploadmsg(11);
  69. }
  70. }
  71. updatemembercount($_G['uid'], array('todayattachs' => 1, 'todayattachsize' => $upload->attach['size']));
  72. $upload->save();
  73. if($upload->error() == -103) {
  74. return $this->uploadmsg(8);
  75. } elseif($upload->error()) {
  76. return $this->uploadmsg(9);
  77. }
  78. $thumb = $remote = $width = 0;
  79. if($_GET['type'] == 'image' && !$upload->attach['isimage']) {
  80. return $this->uploadmsg(7);
  81. }
  82. if($upload->attach['isimage']) {
  83. if(!in_array($upload->attach['imageinfo']['2'], array(1,2,3,6))) {
  84. return $this->uploadmsg(7);
  85. }
  86. if($_G['setting']['showexif']) {
  87. require_once libfile('function/attachment');
  88. $exif = getattachexif(0, $upload->attach['target']);
  89. }
  90. if($_G['setting']['thumbsource'] || $_G['setting']['thumbstatus']) {
  91. require_once libfile('class/image');
  92. $image = new image;
  93. }
  94. if($_G['setting']['thumbsource'] && $_G['setting']['sourcewidth'] && $_G['setting']['sourceheight']) {
  95. $thumb = $image->Thumb($upload->attach['target'], '', $_G['setting']['sourcewidth'], $_G['setting']['sourceheight'], 1, 1) ? 1 : 0;
  96. $width = $image->imginfo['width'];
  97. $upload->attach['size'] = $image->imginfo['size'];
  98. }
  99. if($_G['setting']['thumbstatus']) {
  100. $thumb = $image->Thumb($upload->attach['target'], '', $_G['setting']['thumbwidth'], $_G['setting']['thumbheight'], $_G['setting']['thumbstatus'], 0) ? 1 : 0;
  101. $width = $image->imginfo['width'];
  102. }
  103. if($_G['setting']['thumbsource'] || !$_G['setting']['thumbstatus']) {
  104. list($width) = @getimagesize($upload->attach['target']);
  105. }
  106. }
  107. if($_GET['type'] != 'image' && $upload->attach['isimage']) {
  108. $upload->attach['isimage'] = -1;
  109. }
  110. $this->aid = $aid = getattachnewaid($this->uid);
  111. $insert = array(
  112. 'aid' => $aid,
  113. 'dateline' => $_G['timestamp'],
  114. 'filename' => dhtmlspecialchars(censor($upload->attach['name'])),
  115. 'filesize' => $upload->attach['size'],
  116. 'attachment' => $upload->attach['attachment'],
  117. 'isimage' => $upload->attach['isimage'],
  118. 'uid' => $this->uid,
  119. 'thumb' => $thumb,
  120. 'remote' => $remote,
  121. 'width' => $width,
  122. );
  123. C::t('forum_attachment_unused')->insert($insert);
  124. if($upload->attach['isimage'] && $_G['setting']['showexif']) {
  125. C::t('forum_attachment_exif')->insert($aid, $exif);
  126. }
  127. return $this->uploadmsg(0);
  128. }
  129. function uploadmsg($statusid) {
  130. global $_G;
  131. $this->error_sizelimit = !empty($this->error_sizelimit) ? $this->error_sizelimit : 0;
  132. if($this->getaid) {
  133. $this->getaid = $statusid ? -$statusid : $this->aid;
  134. return;
  135. }
  136. if($this->simple == 1) {
  137. echo 'DISCUZUPLOAD|'.$statusid.'|'.$this->aid.'|'.$this->attach['isimage'].'|'.$this->error_sizelimit;
  138. } elseif($this->simple == 2) {
  139. echo 'DISCUZUPLOAD|'.($_GET['type'] == 'image' ? '1' : '0').'|'.$statusid.'|'.$this->aid.'|'.$this->attach['isimage'].'|'.($this->attach['isimage'] ? $this->attach['attachment'] : '').'|'.$this->attach['name'].'|'.$this->error_sizelimit;
  140. } else {
  141. echo $statusid ? -$statusid : $this->aid;
  142. }
  143. exit;
  144. }
  145. }
  146. ?>