attachment.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640
  1. <?php
  2. class attachment
  3. {
  4. var $contentid;
  5. var $module;
  6. var $catid;
  7. var $attachments;
  8. var $field;
  9. var $imageexts = array('xls,xlsx');
  10. var $alowexts = array();
  11. var $uploadedfiles = array();
  12. var $downloadedfiles = array();
  13. var $error;
  14. var $upload_root;
  15. var $siteid;
  16. var $site = array();
  17. var $upload_dir;
  18. var $uploadeds;
  19. function __construct($catid = 0, $upload_dir = 'data/')
  20. {
  21. $this->catid = intval($catid);
  22. // $this->siteid = intval($siteid) == 0 ? 1 : intval($siteid);
  23. // $this->module = $module ? $module : 'content';
  24. // pc_base::load_sys_func('dir');
  25. // pc_base::load_sys_class('image', '', '0');
  26. $this->upload_root = Doo::conf()->SITE_PATH;
  27. $this->upload_func = 'move_uploaded_file';
  28. // $this->upload_func = 'copy';
  29. $this->upload_dir = $upload_dir;
  30. }
  31. function setUploadDir($upload_dir = 'files/')
  32. {
  33. $this->upload_dir = $upload_dir;
  34. }
  35. /**
  36. * 附件上传方法
  37. * @param $field 上传字段
  38. * @param $alowexts 允许上传类型
  39. * @param $maxsize 最大上传大小
  40. * @param $overwrite 是否覆盖原有文件
  41. * @param $thumb_setting 缩略图设置
  42. * @param $watermark_enable 是否添加水印
  43. */
  44. function upload($field, $alowexts = '', $maxsize = 0, $overwrite = 0, $thumb_setting = array(), $watermark_enable = 1, $ip = '')
  45. {
  46. if (!isset($_FILES[$field])) {
  47. $this->error = UPLOAD_ERR_OK;
  48. return false;
  49. }
  50. $this->field = $field;
  51. $this->savepath = $this->upload_root . $this->upload_dir . date('Y/md/');
  52. $this->alowexts = $alowexts;
  53. $this->maxsize = $maxsize;
  54. $this->overwrite = $overwrite;
  55. $uploadfiles = array();
  56. $description = isset($GLOBALS[$field . '_description']) ? $GLOBALS[$field . '_description'] : array();
  57. // $this->uploads = count($_FILES[$field]['error']);
  58. // if ($this->uploads >= 2) {
  59. if (is_array($_FILES[$field]['error'])) {
  60. $this->uploads = count($_FILES[$field]['error']);
  61. foreach ($_FILES[$field]['error'] as $key => $error) {
  62. if ($error === UPLOAD_ERR_NO_FILE)
  63. continue;
  64. if ($error !== UPLOAD_ERR_OK) {
  65. $this->error = $error;
  66. return false;
  67. }
  68. $uploadfiles[$key] = array('tmp_name' => $_FILES[$field]['tmp_name'][$key], 'name' => $_FILES[$field]['name'][$key], 'type' => $_FILES[$field]['type'][$key], 'size' => $_FILES[$field]['size'][$key], 'error' => $_FILES[$field]['error'][$key], 'description' => $description[$key]);
  69. }
  70. } else {
  71. $this->uploads = 1;
  72. if (!$description)
  73. $description = '';
  74. $uploadfiles[0] = array('tmp_name' => $_FILES[$field]['tmp_name'], 'name' => $_FILES[$field]['name'], 'type' => $_FILES[$field]['type'], 'size' => $_FILES[$field]['size'], 'error' => $_FILES[$field]['error'], 'description' => $description);
  75. }
  76. if (!$this->dir_create($this->savepath)) {
  77. $this->error = '8';
  78. return false;
  79. }
  80. if (!is_dir($this->savepath)) {
  81. $this->error = '8';
  82. return false;
  83. }
  84. @chmod($this->savepath, 0777);
  85. if (!is_writeable($this->savepath)) {
  86. $this->error = '9';
  87. return false;
  88. }
  89. // if (!$this->is_allow_upload()) {
  90. // $this->error = '13';
  91. // return false;
  92. // }
  93. $aids = array();
  94. foreach ($uploadfiles as $k => $file) {
  95. $fileext = $this->fileext($file['name']);
  96. if ($file['error'] != 0) {
  97. $this->error = $file['error'];
  98. return false;
  99. }
  100. // if (!preg_match("/^(" . $this->alowexts . ")$/", $fileext)) {
  101. // $this->error = '10';
  102. // return false;
  103. // }
  104. if ($this->maxsize && $file['size'] > $this->maxsize) {
  105. $this->error = '11';
  106. return false;
  107. }
  108. if (!$this->isuploadedfile($file['tmp_name'])) {
  109. $this->error = '12';
  110. return false;
  111. }
  112. $temp_filename = $this->getname($fileext);
  113. $savefile = $this->savepath . $temp_filename;
  114. $savefile = preg_replace("/(php|phtml|php3|php4|jsp|exe|dll|asp|cer|asa|shtml|shtm|aspx|asax|cgi|fcgi|pl)(\.|$)/i", "_\\1\\2", $savefile);
  115. $filepath = preg_replace($this->new_addslashes("|^" . $this->upload_root . "|"), "", $savefile);
  116. if (!$this->overwrite && file_exists($savefile))
  117. continue;
  118. $upload_func = $this->upload_func;
  119. if ($upload_func($file['tmp_name'], $savefile)) {
  120. // $this->uploadeds++;
  121. @chmod($savefile, 0777);
  122. @unlink($file['tmp_name']);
  123. // $file['name'] = iconv("utf-8", 'sdsdf', $file['name']);
  124. $uploadedfile = array('filename' => $file['name'], 'filepath' => $filepath, 'filesize' => $file['size'], 'fileext' => $fileext, 'uploadip' => $ip, 'uploadtime' => time());
  125. // error_log(var_export($uploadedfile, TRUE), 3, '/opt/WebRoot/wenku/data/upArray.txt');
  126. // $thumb_enable = is_array($thumb_setting) && ($thumb_setting[0] > 0 || $thumb_setting[1] > 0 ) ? 1 : 0;
  127. // $image = new image($thumb_enable, $this->siteid);
  128. // if ($thumb_enable) {
  129. // $image->thumb($savefile, '', $thumb_setting[0], $thumb_setting[1]);
  130. // }
  131. // if ($watermark_enable) {
  132. // $image->watermark($savefile, $savefile);
  133. // }
  134. // $aids[] = $this->add($uploadedfile);
  135. }
  136. }
  137. return $uploadedfile;
  138. }
  139. /**
  140. * 附件上传方法
  141. * @param $field 上传字段
  142. * @param $alowexts 允许上传类型
  143. * @param $maxsize 最大上传大小
  144. * @param $overwrite 是否覆盖原有文件
  145. */
  146. function uploadMut($field, $alowexts = '', $maxsize = 0, $overwrite = 0)
  147. {
  148. if (!isset($_FILES[$field])) {
  149. $this->error = UPLOAD_ERR_OK;
  150. return false;
  151. }
  152. $this->field = $field;
  153. $this->savepath = $this->upload_root . $this->upload_dir . date('Y/md/');
  154. $this->alowexts = $alowexts;
  155. $this->maxsize = $maxsize;
  156. $this->overwrite = $overwrite;
  157. $uploadfiles = array();
  158. $description = isset($GLOBALS[$field . '_description']) ? $GLOBALS[$field . '_description'] : array();
  159. if (is_array($_FILES[$field]['error'])) {
  160. $this->uploads = count($_FILES[$field]['error']);
  161. foreach ($_FILES[$field]['error'] as $key => $error) {
  162. if ($error === UPLOAD_ERR_NO_FILE)
  163. continue;
  164. if ($error !== UPLOAD_ERR_OK) {
  165. $this->error = $error;
  166. return false;
  167. }
  168. $uploadfiles[$key] = array('tmp_name' => $_FILES[$field]['tmp_name'][$key], 'name' => $_FILES[$field]['name'][$key], 'type' => $_FILES[$field]['type'][$key], 'size' => $_FILES[$field]['size'][$key], 'error' => $_FILES[$field]['error'][$key]);
  169. }
  170. } else {
  171. $this->uploads = 1;
  172. if (!$description)
  173. $description = '';
  174. $uploadfiles[0] = array('tmp_name' => $_FILES[$field]['tmp_name'], 'name' => $_FILES[$field]['name'], 'type' => $_FILES[$field]['type'], 'size' => $_FILES[$field]['size'], 'error' => $_FILES[$field]['error'], 'description' => $description);
  175. }
  176. if (!$this->dir_create($this->savepath)) {
  177. $this->error = '8';
  178. return false;
  179. }
  180. if (!is_dir($this->savepath)) {
  181. $this->error = '8';
  182. return false;
  183. }
  184. // @chmod($this->savepath, 0777);
  185. if (!is_writeable($this->savepath)) {
  186. $this->error = '9';
  187. return false;
  188. }
  189. $aids = array();
  190. foreach ($uploadfiles as $k => $file) {
  191. $fileext = $this->fileext2($file['name']);
  192. if ($file['error'] != 0) {
  193. $this->error = $file['error'];
  194. // echo $this->error;
  195. return false;
  196. }
  197. // if (!preg_match("/^(" . $this->alowexts . ")$/", $fileext)) {
  198. // $this->error = '10';
  199. // echo $this->error;
  200. // return false;
  201. // }
  202. if ($this->maxsize && $file['size'] > $this->maxsize) {
  203. $this->error = '11';
  204. // echo $this->error;
  205. return false;
  206. }
  207. if (!$this->isuploadedfile($file['tmp_name'])) {
  208. $this->error = '12';
  209. // echo $this->error;
  210. return false;
  211. }
  212. $temp_filename = $this->getname($fileext);
  213. $savefile = $this->savepath . $temp_filename;
  214. $savefile = preg_replace("/(php|phtml|php3|php4|jsp|exe|dll|asp|cer|asa|shtml|shtm|aspx|asax|cgi|fcgi|pl)(\.|$)/i", "_\\1\\2", $savefile);
  215. $filepath = preg_replace($this->new_addslashes("|^" . $this->upload_root . "|"), "", $savefile);
  216. if (!$this->overwrite && file_exists($savefile))
  217. continue;
  218. $upload_func = $this->upload_func;
  219. if (@$upload_func($file['tmp_name'], $savefile)) {
  220. $this->uploadeds++;
  221. @chmod($savefile, 0777);
  222. @unlink($file['tmp_name']);
  223. $file['name'] = $this->safe_replace($file['name']);
  224. $uploadedfile = array('filename' => trim($file['name']), 'filepath' => $filepath, 'filesize' => $file['size'], 'fileext' => $fileext);
  225. $aids[] = $uploadedfile;
  226. }
  227. }
  228. return $aids;
  229. }
  230. /**
  231. * 取得文件扩展
  232. *
  233. * @param $filename 文件名
  234. * @return 扩展名
  235. */
  236. function fileext2($filename)
  237. {
  238. return strtolower(trim(substr(strrchr($filename, '.'), 1, 10)));
  239. }
  240. /**
  241. * 安全过滤函数
  242. *
  243. * @param $string
  244. * @return string
  245. */
  246. function safe_replace($string)
  247. {
  248. $string = str_replace('%20', '', $string);
  249. $string = str_replace('%27', '', $string);
  250. $string = str_replace('%2527', '', $string);
  251. $string = str_replace('*', '', $string);
  252. $string = str_replace('"', '&quot;', $string);
  253. $string = str_replace("'", '', $string);
  254. $string = str_replace('"', '', $string);
  255. $string = str_replace(';', '', $string);
  256. $string = str_replace('<', '&lt;', $string);
  257. $string = str_replace('>', '&gt;', $string);
  258. $string = str_replace("{", '', $string);
  259. $string = str_replace('}', '', $string);
  260. return $string;
  261. }
  262. /**
  263. * 返回经addslashes处理过的字符串或数组
  264. * @param $string 需要处理的字符串或数组
  265. * @return mixed
  266. */
  267. function new_addslashes($string)
  268. {
  269. if (!is_array($string))
  270. return addslashes($string);
  271. foreach ($string as $key => $val)
  272. $string[$key] = new_addslashes($val);
  273. return $string;
  274. }
  275. /**
  276. * 取得文件扩展
  277. *
  278. * @param $filename 文件名
  279. * @return 扩展名
  280. */
  281. function fileext($filename)
  282. {
  283. $pathinfo = pathinfo($filename);
  284. // return strtolower(trim(substr(mb_strrchr($filename, '.'), 1, 10)));
  285. return $pathinfo['extension'];
  286. }
  287. /**
  288. * 创建目录
  289. *
  290. * @param string $path 路径
  291. * @param string $mode 属性
  292. * @return string 如果已经存在则返回true,否则为flase
  293. */
  294. function dir_create($path, $mode = 0777)
  295. {
  296. if (is_dir($path))
  297. return TRUE;
  298. // $ftp_enable = 0;
  299. $path = $this->dir_path($path);
  300. $parent = dirname($path);
  301. if (!is_dir($parent))
  302. @mkdir($parent, 0777, true);
  303. @mkdir($path, 0777, true);
  304. // $temp = explode('/', $path);
  305. // $cur_dir = '';
  306. // $max = count($temp) - 1;
  307. // for ($i = 0; $i < $max; $i++) {
  308. // if (empty($temp[$i]))
  309. // continue;
  310. // $cur_dir .= $temp[$i] . '/';
  311. // if (@is_dir($cur_dir))
  312. // continue;
  313. //// error_log($cur_dir, 3, '/opt/WebRoot/wenku/data/4mkdir.txt');
  314. // @mkdir($cur_dir, 0777, true);
  315. // @chmod($cur_dir, 0777);
  316. // }
  317. return is_dir($path);
  318. }
  319. /**
  320. * 转化 \ 为 /
  321. *
  322. * @param string $path 路径
  323. * @return string 路径
  324. */
  325. function dir_path($path)
  326. {
  327. $path = str_replace('\\', '/', $path);
  328. if (substr($path, -1) != '/')
  329. $path = $path . '/';
  330. return $path;
  331. }
  332. /**
  333. * 附件下载
  334. * Enter description here ...
  335. * @param $field 预留字段
  336. * @param $value 传入下载内容
  337. * @param $watermark 是否加入水印
  338. * @param $ext 下载扩展名
  339. * @param $absurl 绝对路径
  340. * @param $basehref
  341. */
  342. function download($field, $value, $watermark = '0', $ext = 'gif|jpg|jpeg|bmp|png', $absurl = '', $basehref = '')
  343. {
  344. global $image_d;
  345. $this->att_db = pc_base::load_model('attachment_model');
  346. $upload_url = pc_base::load_config('system', 'upload_url');
  347. $this->field = $field;
  348. $dir = date('Y/md/');
  349. $uploadpath = $upload_url . $dir;
  350. $uploaddir = $this->upload_root . $dir;
  351. $string = new_stripslashes($value);
  352. if (!preg_match_all("/(href|src)=([\"|']?)([^ \"'>]+\.($ext))\\2/i", $string, $matches))
  353. return $value;
  354. $remotefileurls = array();
  355. foreach ($matches[3] as $matche) {
  356. if (strpos($matche, '://') === false)
  357. continue;
  358. dir_create($uploaddir);
  359. $remotefileurls[$matche] = $this->fillurl($matche, $absurl, $basehref);
  360. }
  361. unset($matches, $string);
  362. $remotefileurls = array_unique($remotefileurls);
  363. $oldpath = $newpath = array();
  364. foreach ($remotefileurls as $k => $file) {
  365. if (strpos($file, '://') === false || strpos($file, $upload_url) !== false)
  366. continue;
  367. $filename = fileext($file);
  368. $file_name = basename($file);
  369. $filename = $this->getname($filename);
  370. $newfile = $uploaddir . $filename;
  371. $upload_func = $this->upload_func;
  372. if ($upload_func($file, $newfile)) {
  373. $oldpath[] = $k;
  374. $GLOBALS['downloadfiles'][] = $newpath[] = $uploadpath . $filename;
  375. @chmod($newfile, 0777);
  376. $fileext = fileext($filename);
  377. if ($watermark) {
  378. watermark($newfile, $newfile, $this->siteid);
  379. }
  380. $filepath = $dir . $filename;
  381. $downloadedfile = array('filename' => $filename, 'filepath' => $filepath, 'filesize' => filesize($newfile), 'fileext' => $fileext);
  382. $aid = $this->add($downloadedfile);
  383. $this->downloadedfiles[$aid] = $filepath;
  384. }
  385. }
  386. return str_replace($oldpath, $newpath, $value);
  387. }
  388. /**
  389. * 附件删除方法
  390. * @param $where 删除sql语句
  391. */
  392. function delete($where)
  393. {
  394. $this->att_db = pc_base::load_model('attachment_model');
  395. $result = $this->att_db->select($where);
  396. foreach ($result as $r) {
  397. $image = $this->upload_root . $r['filepath'];
  398. @unlink($image);
  399. $thumbs = glob(dirname($image) . '/*' . basename($image));
  400. if ($thumbs)
  401. foreach ($thumbs as $thumb)
  402. @unlink($thumb);
  403. }
  404. return $this->att_db->delete($where);
  405. }
  406. /**
  407. * 附件添加如数据库
  408. * @param $uploadedfile 附件信息
  409. */
  410. function add($Arrupfileinfo)
  411. {
  412. Doo::loadModel('attachment');
  413. $attaobj = new AttachmentModel();
  414. $aid = $attaobj->add_attachment($Arrupfileinfo);
  415. return $aid;
  416. }
  417. function set_userid($userid)
  418. {
  419. $this->userid = $userid;
  420. }
  421. /**
  422. * 获取缩略图地址..
  423. * @param $image 图片路径
  424. */
  425. function get_thumb($image)
  426. {
  427. return str_replace('.', '_thumb.', $image);
  428. }
  429. /**
  430. * 获取附件名称
  431. * @param $fileext 附件扩展名
  432. */
  433. function getname($fileext)
  434. {
  435. return date('Ymdhis') . rand(100, 999) . '.' . $fileext;
  436. }
  437. /**
  438. * 返回附件大小
  439. * @param $filesize 图片大小
  440. */
  441. function size($filesize)
  442. {
  443. if ($filesize >= 1073741824) {
  444. $filesize = round($filesize / 1073741824 * 100) / 100 . ' GB';
  445. } elseif ($filesize >= 1048576) {
  446. $filesize = round($filesize / 1048576 * 100) / 100 . ' MB';
  447. } elseif ($filesize >= 1024) {
  448. $filesize = round($filesize / 1024 * 100) / 100 . ' KB';
  449. } else {
  450. $filesize = $filesize . ' Bytes';
  451. }
  452. return $filesize;
  453. }
  454. /**
  455. * 判断文件是否是通过 HTTP POST 上传的
  456. *
  457. * @param string $file 文件地址
  458. * @return bool 所给出的文件是通过 HTTP POST 上传的则返回 TRUE
  459. */
  460. function isuploadedfile($file)
  461. {
  462. return is_uploaded_file($file) || is_uploaded_file(str_replace('\\\\', '\\', $file));
  463. }
  464. /**
  465. * 补全网址
  466. *
  467. * @param string $surl 源地址
  468. * @param string $absurl 相对地址
  469. * @param string $basehref 网址
  470. * @return string 网址
  471. */
  472. function fillurl($surl, $absurl, $basehref = '')
  473. {
  474. if ($basehref != '') {
  475. $preurl = strtolower(substr($surl, 0, 6));
  476. if ($preurl == 'http://' || $preurl == 'ftp://' || $preurl == 'mms://' || $preurl == 'rtsp://' || $preurl == 'thunde' || $preurl == 'emule://' || $preurl == 'ed2k://')
  477. return $surl;
  478. else
  479. return $basehref . '/' . $surl;
  480. }
  481. $i = 0;
  482. $dstr = '';
  483. $pstr = '';
  484. $okurl = '';
  485. $pathStep = 0;
  486. $surl = trim($surl);
  487. if ($surl == '')
  488. return '';
  489. $urls = @parse_url(SITE_URL);
  490. $HomeUrl = $urls['host'];
  491. $BaseUrlPath = $HomeUrl . $urls['path'];
  492. $BaseUrlPath = preg_replace("/\/([^\/]*)\.(.*)$/", '/', $BaseUrlPath);
  493. $BaseUrlPath = preg_replace("/\/$/", '', $BaseUrlPath);
  494. $pos = strpos($surl, '#');
  495. if ($pos > 0)
  496. $surl = substr($surl, 0, $pos);
  497. if ($surl[0] == '/') {
  498. $okurl = 'http://' . $HomeUrl . '/' . $surl;
  499. } elseif ($surl[0] == '.') {
  500. if (strlen($surl) <= 2)
  501. return '';
  502. elseif ($surl[0] == '/') {
  503. $okurl = 'http://' . $BaseUrlPath . '/' . substr($surl, 2, strlen($surl) - 2);
  504. } else {
  505. $urls = explode('/', $surl);
  506. foreach ($urls as $u) {
  507. if ($u == "..")
  508. $pathStep++;
  509. else if ($i < count($urls) - 1)
  510. $dstr .= $urls[$i] . '/';
  511. else
  512. $dstr .= $urls[$i];
  513. $i++;
  514. }
  515. $urls = explode('/', $BaseUrlPath);
  516. if (count($urls) <= $pathStep)
  517. return '';
  518. else {
  519. $pstr = 'http://';
  520. for ($i = 0; $i < count($urls) - $pathStep; $i++) {
  521. $pstr .= $urls[$i] . '/';
  522. }
  523. $okurl = $pstr . $dstr;
  524. }
  525. }
  526. } else {
  527. $preurl = strtolower(substr($surl, 0, 6));
  528. if (strlen($surl) < 7)
  529. $okurl = 'http://' . $BaseUrlPath . '/' . $surl;
  530. elseif ($preurl == "http:/" || $preurl == 'ftp://' || $preurl == 'mms://' || $preurl == "rtsp://" || $preurl == 'thunde' || $preurl == 'emule:' || $preurl == 'ed2k:/')
  531. $okurl = $surl;
  532. else
  533. $okurl = 'http://' . $BaseUrlPath . '/' . $surl;
  534. }
  535. $preurl = strtolower(substr($okurl, 0, 6));
  536. if ($preurl == 'ftp://' || $preurl == 'mms://' || $preurl == 'rtsp://' || $preurl == 'thunde' || $preurl == 'emule:' || $preurl == 'ed2k:/') {
  537. return $okurl;
  538. } else {
  539. $okurl = preg_replace('/^(http:\/\/)/i', '', $okurl);
  540. $okurl = preg_replace('/\/{1,}/i', '/', $okurl);
  541. return 'http://' . $okurl;
  542. }
  543. }
  544. /**
  545. * 是否允许上传
  546. */
  547. function is_allow_upload()
  548. {
  549. if ($_groupid == 1)
  550. return true;
  551. $starttime = SYS_TIME - 86400;
  552. $site_setting = $this->_get_site_setting($this->siteid);
  553. return ($uploads < $site_setting['upload_maxsize']);
  554. }
  555. /**
  556. * 返回错误信息
  557. */
  558. function error()
  559. {
  560. return $this->error;
  561. }
  562. /**
  563. * ck编辑器返回
  564. * @param $fn
  565. * @param $fileurl 路径
  566. * @param $message 显示信息
  567. */
  568. function mkhtml($fn, $fileurl, $message)
  569. {
  570. $str = '<script type="text/javascript">window.parent.CKEDITOR.tools.callFunction(' . $fn . ', \'' . $fileurl . '\', \'' . $message . '\');</script>';
  571. exit($str);
  572. }
  573. /**
  574. * flash上传调试方法
  575. * @param $id
  576. */
  577. function uploaderror($id = 0)
  578. {
  579. file_put_contents(PHPCMS_PATH . 'xxx.txt', $id);
  580. }
  581. /**
  582. * 获取站点配置信息
  583. * @param $siteid 站点id
  584. */
  585. private function _get_site_setting($siteid)
  586. {
  587. $siteinfo = getcache('sitelist', 'commons');
  588. return string2array($siteinfo[$siteid]['setting']);
  589. }
  590. /**
  591. * Get client's IP
  592. * @return string
  593. */
  594. public function clientIP()
  595. {
  596. if (getenv('HTTP_CLIENT_IP') && strcasecmp(getenv('HTTP_CLIENT_IP'), 'unknown')) {
  597. return getenv('HTTP_CLIENT_IP');
  598. } elseif (getenv('HTTP_X_FORWARDED_FOR') && strcasecmp(getenv('HTTP_X_FORWARDED_FOR'), 'unknown')) {
  599. return getenv('HTTP_X_FORWARDED_FOR');
  600. } elseif (getenv('REMOTE_ADDR') && strcasecmp(getenv('REMOTE_ADDR'), 'unknown')) {
  601. return getenv('REMOTE_ADDR');
  602. } elseif (isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], 'unknown')) {
  603. return $_SERVER['REMOTE_ADDR'];
  604. }
  605. }
  606. }
  607. ?>