forumimage.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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: forumimage.php 32489 2013-01-29 03:57:16Z monkey $
  7. */
  8. if(!defined('IN_MOBILE_API')) {
  9. exit('Access Denied');
  10. }
  11. include_once 'forum.php';
  12. class mobile_api {
  13. function common() {
  14. global $_G;
  15. if(!defined('IN_DISCUZ') || empty($_GET['aid']) || empty($_GET['size']) || empty($_GET['key'])) {
  16. header('location: '.$_G['siteurl'].'static/image/common/none.gif');
  17. exit;
  18. }
  19. $allowsize = array('960x960', '268x380', '266x698', '2000x2000');
  20. if(!in_array($_GET['size'], $allowsize)) {
  21. header('location: '.$_G['siteurl'].'static/image/common/none.gif');
  22. exit;
  23. }
  24. $nocache = !empty($_GET['nocache']) ? 1 : 0;
  25. $daid = intval($_GET['aid']);
  26. $type = !empty($_GET['type']) ? $_GET['type'] : 'fixwr';
  27. list($w, $h) = explode('x', $_GET['size']);
  28. $dw = intval($w);
  29. $dh = intval($h);
  30. $thumbfile = 'image/'.$daid.'_'.$dw.'_'.$dh.'.jpg';
  31. $parse = parse_url($_G['setting']['attachurl']);
  32. $attachurl = !isset($parse['host']) ? $_G['siteurl'].$_G['setting']['attachurl'] : $_G['setting']['attachurl'];
  33. if(!$nocache) {
  34. if(file_exists($_G['setting']['attachdir'].$thumbfile)) {
  35. dheader('location: '.$attachurl.$thumbfile);
  36. }
  37. }
  38. define('NOROBOT', TRUE);
  39. $id = !empty($_GET['atid']) ? $_GET['atid'] : $daid;
  40. if(md5($id.'|'.$dw.'|'.$dh) != $_GET['key']) {
  41. dheader('location: '.$_G['siteurl'].'static/image/common/none.gif');
  42. }
  43. if($attach = C::t('forum_attachment_n')->fetch('aid:'.$daid, $daid, array(1, -1))) {
  44. if(!$dw && !$dh && $attach['tid'] != $id) {
  45. dheader('location: '.$_G['siteurl'].'static/image/common/none.gif');
  46. }
  47. dheader('Expires: '.gmdate('D, d M Y H:i:s', TIMESTAMP + 3600).' GMT');
  48. if($attach['remote']) {
  49. $filename = $_G['setting']['ftp']['attachurl'].'forum/'.$attach['attachment'];
  50. } else {
  51. $filename = $_G['setting']['attachdir'].'forum/'.$attach['attachment'];
  52. }
  53. require_once libfile('class/image');
  54. $img = new image;
  55. if($img->Thumb($filename, $thumbfile, $w, $h, $type)) {
  56. if($nocache) {
  57. dheader('Content-Type: image');
  58. @readfile($_G['setting']['attachdir'].$thumbfile);
  59. @unlink($_G['setting']['attachdir'].$thumbfile);
  60. } else {
  61. dheader('location: '.$attachurl.$thumbfile);
  62. }
  63. } else {
  64. dheader('Content-Type: image');
  65. @readfile($filename);
  66. }
  67. }
  68. exit;
  69. }
  70. }
  71. ?>