PageRenderTime 48ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/mode/attachment.class.php

http://xklog.googlecode.com/
PHP | 89 lines | 71 code | 14 blank | 4 comment | 17 complexity | 4753c4e6686896ad2a6d159c5df2ad04 MD5 | raw file
Possible License(s): AGPL-1.0
  1. <?php
  2. !defined('IN_NOVA') && exit('Access Denied!');
  3. class Attachement {
  4. public function start() {
  5. $fileid = getGP('id','G','int');
  6. $view = getGP('view','G');
  7. if( !$fileid ) {
  8. @header('content-type: text/html; charset=utf-8');
  9. exit('?????');
  10. }
  11. //???
  12. if( !isset( $_SERVER['HTTP_REFERER'] ) ) access_denied();
  13. $allow_host = $_CACHE['set'][0]['domain'];
  14. $referer = parse_url($_SERVER['HTTP_REFERER']);
  15. if ( 'http://' . $referer['host'] . '/' != $allow_host ) {
  16. access_denied();
  17. }
  18. $file = $db->fetch_one_array("SELECT ul_id,ul_filepath,ul_filetype,ul_fileext,ul_filesize,ul_thumb,ul_time FROM `" . PREFIX_STR . "upload` WHERE ul_id = $fileid");
  19. if( !isset( $file['ul_filepath'] ) ) {
  20. @header('content-type: text/html; charset=utf-8');
  21. exit('?????????????????');
  22. }
  23. $file['ul_filepath'] = XKLOG_ROOT . $file['ul_filepath'];
  24. if ( !$file ) {
  25. access_denied();
  26. } else {
  27. //????getimagesize??????????????????????????
  28. $isimage = false;
  29. if ( stristr( $file['ul_filetype'], 'image' ) ) {
  30. $imginfo = @getimagesize( $file['ul_filepath'] );
  31. if ( $imginfo[2] && $imginfo['bits'] ) {
  32. $isimage = true;
  33. }
  34. unset( $imginfo );
  35. }
  36. // ???????inline?????attachment?????
  37. $disposition = $isimage ? 'inline' : 'attachment';
  38. // ????????
  39. if ( $disposition == 'attachment' ) {
  40. $db->query("UPDATE `" . PREFIX_STR . "upload` SET ul_downloads = ul_downloads + 1 WHERE ul_id = $fileid");
  41. } elseif ( $view == 'thumb' && !empty( $file['ul_thumb'] ) ) {
  42. $file['ul_filepath'] = $file['ul_thumb'];
  43. }
  44. $file['ul_filetype'] = $file['ul_filetype'] ? $file['ul_filetype'] : 'application/octet-stream';
  45. $file_name = basename( get_date( 'YmdHis',PHP_TIME ) . mt_rand(10,99) . '.' . $file['ul_fileext'] );
  46. if ( is_readable( $file['ul_filepath'] ) ) {
  47. ob_end_clean();
  48. header( 'Cache-control: max-age=31536000' );
  49. header( 'Expires: ' . get_date('D, d M Y H:i:s',PHP_TIME + 31536000) . ' GMT' );
  50. header( 'Last-Modified: ' . get_date('D, d M Y H:i:s',$file['ul_time']) . ' GMT' );
  51. header( 'content-Encoding: none' );
  52. header( 'content-type: ' . $file['ul_filetype'] );
  53. header( 'content-Disposition: ' . $disposition . '; filename=' . urlencode( $file_name ) );
  54. header( 'content-Length: ' . $file['ul_filesize'] );
  55. $fp = fopen( $file['ul_filepath'], 'rb' );
  56. fpassthru($fp);
  57. fclose($fp);
  58. exit;
  59. } else {
  60. @header('content-type: text/html; charset=utf-8');
  61. exit('???????');
  62. }
  63. }
  64. }
  65. private function access_denied() {
  66. header('content-Encoding: none');
  67. header('content-type: image/gif');
  68. header('content-Disposition: inline; filename="open_denied.gif"');
  69. $fp = fopen('../images/open_denied.gif','rb');
  70. fpassthru($fp);
  71. fclose($fp);
  72. exit();
  73. }
  74. }
  75. ?>