misc_swfupload.php 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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: misc_swfupload.php 35377 2015-07-07 05:20:23Z nemohou $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. $_G['uid'] = intval($_POST['uid']);
  12. if((empty($_G['uid']) && $_GET['operation'] != 'upload') || $_POST['hash'] != md5(substr(md5($_G['config']['security']['authkey']), 8).$_G['uid'])) {
  13. exit();
  14. } else {
  15. if($_G['uid']) {
  16. $_G['member'] = getuserbyuid($_G['uid']);
  17. }
  18. $_G['groupid'] = $_G['member']['groupid'];
  19. loadcache('usergroup_'.$_G['member']['groupid']);
  20. $_G['group'] = $_G['cache']['usergroup_'.$_G['member']['groupid']];
  21. }
  22. if($_GET['operation'] == 'upload') {
  23. if(empty($_GET['simple'])) {
  24. $_FILES['Filedata']['name'] = diconv(urldecode($_FILES['Filedata']['name']), 'UTF-8');
  25. $_FILES['Filedata']['type'] = $_GET['filetype'];
  26. }
  27. $forumattachextensions = '';
  28. $fid = intval($_GET['fid']);
  29. if($fid) {
  30. $forum = $fid != $_G['fid'] ? C::t('forum_forum')->fetch_info_by_fid($fid) : $_G['forum'];
  31. if($forum['status'] == 3 && $forum['level']) {
  32. $levelinfo = C::t('forum_grouplevel')->fetch($forum['level']);
  33. if($postpolicy = $levelinfo['postpolicy']) {
  34. $postpolicy = dunserialize($postpolicy);
  35. $forumattachextensions = $postpolicy['attachextensions'];
  36. }
  37. } else {
  38. $forumattachextensions = $forum['attachextensions'];
  39. }
  40. if($forumattachextensions) {
  41. $_G['group']['attachextensions'] = $forumattachextensions;
  42. }
  43. }
  44. $upload = new forum_upload();
  45. } elseif($_GET['operation'] == 'poll') {
  46. $upload = new discuz_upload();
  47. $_FILES["Filedata"]['name'] = addslashes(diconv(urldecode($_FILES["Filedata"]['name']), 'UTF-8'));
  48. $upload->init($_FILES['Filedata'], 'forum');
  49. $attach = $upload->attach;
  50. if(!$upload->attach['isimage']) {
  51. $errorcode = 4;
  52. } else {
  53. $upload->save();
  54. $errorcode = 0;
  55. }
  56. if($upload->error()) {
  57. $errorcode = 4;
  58. } else {
  59. if($attach['isimage']) {
  60. require_once libfile('class/image');
  61. $image = new image();
  62. $thumbimgwidth = 300;
  63. $thumbimgheight = 300;
  64. $attach['thumb'] = $image->Thumb($attach['target'], '', $thumbimgwidth, $thumbimgheight, 2);
  65. $image->Watermark($attach['target'], '', 'forum');
  66. $imginfo = @getimagesize($attach['target']);
  67. if($imginfo !== FALSE) {
  68. $attach['width'] = $imginfo[0];
  69. }
  70. }
  71. if(getglobal('setting/ftp/on') && ((!$_G['setting']['ftp']['allowedexts'] && !$_G['setting']['ftp']['disallowedexts']) || ($_G['setting']['ftp']['allowedexts'] && in_array($attach['ext'], $_G['setting']['ftp']['allowedexts'])) || ($_G['setting']['ftp']['disallowedexts'] && !in_array($attach['ext'], $_G['setting']['ftp']['disallowedexts']))) && (!$_G['setting']['ftp']['minsize'] || $attach['size'] >= $_G['setting']['ftp']['minsize'] * 1024)) {
  72. if(ftpcmd('upload', 'forum/'.$attach['attachment']) && (!$attach['thumb'] || ftpcmd('upload', 'forum/'.getimgthumbname($attach['attachment'])))) {
  73. @unlink($_G['setting']['attachdir'].'/forum/'.$attach['attachment']);
  74. @unlink($_G['setting']['attachdir'].'/forum/'.getimgthumbname($attach['attachment']));
  75. $attach['remote'] = 1;
  76. } else {
  77. if(getglobal('setting/ftp/mirror')) {
  78. @unlink($attach['target']);
  79. @unlink(getimgthumbname($attach['target']));
  80. $errorcode = 5;
  81. }
  82. }
  83. }
  84. }
  85. if(!$errorcode) {
  86. $aid = intval($_GET['aid']);
  87. $setarr = array(
  88. 'uid' => $_G['uid'],
  89. 'filename' => $attach['name'],
  90. 'attachment' => $attach['attachment'],
  91. 'filesize' => $attach['size'],
  92. 'thumb' => $attach['thumb'],
  93. 'remote' => $attach['remote'],
  94. 'dateline' => $_G['timestamp'],
  95. 'width' => $attach['width']
  96. );
  97. $image = array();
  98. if($aid) {
  99. $image = C::t('forum_polloption_image')->fetch($aid);
  100. }
  101. if($image['uid'] == $_G['uid']) {
  102. C::t('forum_polloption_image')->update($aid, $setarr);
  103. @unlink($_G['setting']['attachdir'].'/forum/'.$image['attachment']);
  104. @unlink($_G['setting']['attachdir'].'/forum/'.getimgthumbname($image['attachment']));
  105. $attach['attachid'] = $aid;
  106. } else {
  107. $attach['attachid'] = C::t('forum_polloption_image')->insert($setarr, true);
  108. }
  109. require_once libfile('function/home');
  110. $smallimg = pic_get($attach['attachment'], 'forum', $attach['thumb'], $attach['remote']);
  111. $bigimg = pic_get($attach['attachment'], 'forum', 0, $attach['remote']);
  112. echo "{\"aid\":$attach[attachid], \"smallimg\":\"$smallimg\", \"bigimg\":\"$bigimg\", \"errorcode\":$errorcode}";
  113. exit();
  114. } else {
  115. echo "{\"aid\":0, \"errorcode\":$errorcode}";
  116. }
  117. } elseif($_GET['operation'] == 'album') {
  118. $showerror = true;
  119. if(helper_access::check_module('album')) {
  120. require_once libfile('function/spacecp');
  121. if($_FILES["Filedata"]['error']) {
  122. $file = lang('spacecp', 'file_is_too_big');
  123. } else {
  124. require_once libfile('function/home');
  125. $_FILES["Filedata"]['name'] = addslashes(diconv(urldecode($_FILES["Filedata"]['name']), 'UTF-8'));
  126. $file = pic_save($_FILES["Filedata"], 0, '', true, 0);
  127. if(!empty($file) && is_array($file)) {
  128. $url = pic_get($file['filepath'], 'album', $file['thumb'], $file['remote']);
  129. $bigimg = pic_get($file['filepath'], 'album', 0, $file['remote']);
  130. echo "{\"picid\":\"$file[picid]\", \"url\":\"$url\", \"bigimg\":\"$bigimg\"}";
  131. $showerror = false;
  132. }
  133. }
  134. }
  135. if($showerror) {
  136. echo "{\"picid\":\"0\", \"url\":\"0\", \"bigimg\":\"0\"}";
  137. }
  138. } elseif($_GET['operation'] == 'portal') {
  139. $aid = intval($_POST['aid']);
  140. $catid = intval($_POST['catid']);
  141. $msg = '';
  142. $errorcode = 0;
  143. require_once libfile('function/portalcp');
  144. if($aid) {
  145. $article = C::t('portal_article_title')->fetch($aid);
  146. if(!$article) {
  147. $errorcode = 1;
  148. }
  149. if(check_articleperm($catid, $aid, $article, false, true) !== true) {
  150. $errorcode = 2;
  151. }
  152. } else {
  153. if(check_articleperm($catid, $aid, null, false, true) !== true) {
  154. $errorcode = 3;
  155. }
  156. }
  157. $upload = new discuz_upload();
  158. $_FILES["Filedata"]['name'] = addslashes(diconv(urldecode($_FILES["Filedata"]['name']), 'UTF-8'));
  159. $upload->init($_FILES['Filedata'], 'portal');
  160. $attach = $upload->attach;
  161. if(!$upload->error()) {
  162. $upload->save();
  163. }
  164. if($upload->error()) {
  165. $errorcode = 4;
  166. }
  167. if(!$errorcode) {
  168. if($attach['isimage'] && empty($_G['setting']['portalarticleimgthumbclosed'])) {
  169. require_once libfile('class/image');
  170. $image = new image();
  171. $thumbimgwidth = $_G['setting']['portalarticleimgthumbwidth'] ? $_G['setting']['portalarticleimgthumbwidth'] : 300;
  172. $thumbimgheight = $_G['setting']['portalarticleimgthumbheight'] ? $_G['setting']['portalarticleimgthumbheight'] : 300;
  173. $attach['thumb'] = $image->Thumb($attach['target'], '', $thumbimgwidth, $thumbimgheight, 2);
  174. $image->Watermark($attach['target'], '', 'portal');
  175. }
  176. if(getglobal('setting/ftp/on') && ((!$_G['setting']['ftp']['allowedexts'] && !$_G['setting']['ftp']['disallowedexts']) || ($_G['setting']['ftp']['allowedexts'] && in_array($attach['ext'], $_G['setting']['ftp']['allowedexts'])) || ($_G['setting']['ftp']['disallowedexts'] && !in_array($attach['ext'], $_G['setting']['ftp']['disallowedexts']))) && (!$_G['setting']['ftp']['minsize'] || $attach['size'] >= $_G['setting']['ftp']['minsize'] * 1024)) {
  177. if(ftpcmd('upload', 'portal/'.$attach['attachment']) && (!$attach['thumb'] || ftpcmd('upload', 'portal/'.getimgthumbname($attach['attachment'])))) {
  178. @unlink($_G['setting']['attachdir'].'/portal/'.$attach['attachment']);
  179. @unlink($_G['setting']['attachdir'].'/portal/'.getimgthumbname($attach['attachment']));
  180. $attach['remote'] = 1;
  181. } else {
  182. if(getglobal('setting/ftp/mirror')) {
  183. @unlink($attach['target']);
  184. @unlink(getimgthumbname($attach['target']));
  185. $errorcode = 5;
  186. }
  187. }
  188. }
  189. $setarr = array(
  190. 'uid' => $_G['uid'],
  191. 'filename' => $attach['name'],
  192. 'attachment' => $attach['attachment'],
  193. 'filesize' => $attach['size'],
  194. 'isimage' => $attach['isimage'],
  195. 'thumb' => $attach['thumb'],
  196. 'remote' => $attach['remote'],
  197. 'filetype' => $attach['extension'],
  198. 'dateline' => $_G['timestamp'],
  199. 'aid' => $aid
  200. );
  201. $setarr['attachid'] = C::t('portal_attachment')->insert($setarr, true);
  202. if($attach['isimage']) {
  203. require_once libfile('function/home');
  204. $smallimg = pic_get($attach['attachment'], 'portal', $attach['thumb'], $attach['remote']);
  205. $bigimg = pic_get($attach['attachment'], 'portal', 0, $attach['remote']);
  206. $coverstr = addslashes(serialize(array('pic'=>'portal/'.$attach['attachment'], 'thumb'=>$attach['thumb'], 'remote'=>$attach['remote'])));
  207. echo "{\"aid\":$setarr[attachid], \"isimage\":$attach[isimage], \"smallimg\":\"$smallimg\", \"bigimg\":\"$bigimg\", \"errorcode\":$errorcode, \"cover\":\"$coverstr\"}";
  208. exit();
  209. } else {
  210. $fileurl = 'portal.php?mod=attachment&id='.$attach['attachid'];
  211. echo "{\"aid\":$setarr[attachid], \"isimage\":$attach[isimage], \"file\":\"$fileurl\", \"errorcode\":$errorcode}";
  212. exit();
  213. }
  214. } else {
  215. echo "{\"aid\":0, \"errorcode\":$errorcode}";
  216. }
  217. }
  218. ?>