attachment.php 19 KB

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