[985] | 1 | <?php |
---|
| 2 | // +-----------------------------------------------------------------------+ |
---|
| 3 | // | PhpWebGallery - a PHP based picture gallery | |
---|
| 4 | // | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | |
---|
| 5 | // | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net | |
---|
| 6 | // +-----------------------------------------------------------------------+ |
---|
| 7 | // | branch : BSF (Best So Far) |
---|
[986] | 8 | // | file : $URL: trunk/action.php $ |
---|
[985] | 9 | // | last update : $Date: 2007-03-12 22:33:53 +0000 (Mon, 12 Mar 2007) $ |
---|
| 10 | // | last modifier : $Author: rub $ |
---|
[986] | 11 | // | revision : $Rev: 1900 $ |
---|
[985] | 12 | // +-----------------------------------------------------------------------+ |
---|
| 13 | // | This program is free software; you can redistribute it and/or modify | |
---|
| 14 | // | it under the terms of the GNU General Public License as published by | |
---|
| 15 | // | the Free Software Foundation | |
---|
| 16 | // | | |
---|
| 17 | // | This program is distributed in the hope that it will be useful, but | |
---|
| 18 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
| 19 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
| 20 | // | General Public License for more details. | |
---|
| 21 | // | | |
---|
| 22 | // | You should have received a copy of the GNU General Public License | |
---|
| 23 | // | along with this program; if not, write to the Free Software | |
---|
| 24 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
| 25 | // | USA. | |
---|
| 26 | // +-----------------------------------------------------------------------+ |
---|
| 27 | |
---|
[1560] | 28 | define('PHPWG_ROOT_PATH','./'); |
---|
| 29 | include_once(PHPWG_ROOT_PATH.'include/common.inc.php'); |
---|
| 30 | |
---|
| 31 | // Check Access and exit when user status is not ok |
---|
| 32 | check_status(ACCESS_GUEST); |
---|
| 33 | |
---|
[1612] | 34 | function guess_mime_type($ext) |
---|
[985] | 35 | { |
---|
[1612] | 36 | switch ( strtolower($ext) ) |
---|
[1560] | 37 | { |
---|
[1612] | 38 | case "jpe": case "jpeg": |
---|
| 39 | case "jpg": $ctype="image/jpeg"; break; |
---|
| 40 | case "png": $ctype="image/png"; break; |
---|
| 41 | case "gif": $ctype="image/gif"; break; |
---|
| 42 | case "tiff": |
---|
| 43 | case "tif": $ctype="image/tiff"; break; |
---|
| 44 | case "txt": $ctype="text/plain"; break; |
---|
| 45 | case "html": |
---|
| 46 | case "htm": $ctype="text/html"; break; |
---|
| 47 | case "xml": $ctype="text/xml"; break; |
---|
| 48 | case "pdf": $ctype="application/pdf"; break; |
---|
| 49 | case "zip": $ctype="application/zip"; break; |
---|
| 50 | case "ogg": $ctype="application/ogg"; break; |
---|
| 51 | default: $ctype="application/octet-stream"; |
---|
[1560] | 52 | } |
---|
[1612] | 53 | return $ctype; |
---|
| 54 | } |
---|
[985] | 55 | |
---|
[1612] | 56 | function do_error( $code, $str ) |
---|
| 57 | { |
---|
[1643] | 58 | set_status_header( $code ); |
---|
[1612] | 59 | echo $str ; |
---|
| 60 | exit(); |
---|
| 61 | } |
---|
[985] | 62 | |
---|
| 63 | |
---|
[1817] | 64 | if (!isset($_GET['id']) |
---|
| 65 | or !is_numeric($_GET['id']) |
---|
[1612] | 66 | or !isset($_GET['part']) |
---|
| 67 | or !in_array($_GET['part'], array('t','e','i','h') ) ) |
---|
| 68 | { |
---|
| 69 | do_error(400, 'Invalid request - id/part'); |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | $query = ' |
---|
| 73 | SELECT * FROM '. IMAGES_TABLE.' |
---|
[1817] | 74 | WHERE id='.$_GET['id'].' |
---|
[1612] | 75 | ;'; |
---|
| 76 | |
---|
| 77 | $result = pwg_query($query); |
---|
| 78 | $element_info = mysql_fetch_assoc($result); |
---|
| 79 | if ( empty($element_info) ) |
---|
| 80 | { |
---|
| 81 | do_error(404, 'Requested id not found'); |
---|
| 82 | } |
---|
[1678] | 83 | |
---|
| 84 | // $filter['visible_categories'] and $filter['visible_images'] |
---|
[1677] | 85 | // are not used because it's not necessary (filter <> restriction) |
---|
[1616] | 86 | $query=' |
---|
[1817] | 87 | SELECT id |
---|
| 88 | FROM '.CATEGORIES_TABLE.' |
---|
| 89 | INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON category_id = id |
---|
| 90 | WHERE image_id = '.$_GET['id'].' |
---|
| 91 | '.get_sql_condition_FandF( |
---|
| 92 | array('forbidden_categories' => 'category_id'), |
---|
| 93 | ' AND' |
---|
| 94 | ).' |
---|
[1616] | 95 | LIMIT 1 |
---|
| 96 | ;'; |
---|
| 97 | if ( mysql_num_rows(pwg_query($query))<1 ) |
---|
| 98 | { |
---|
| 99 | do_error(401, 'Access denied'); |
---|
| 100 | } |
---|
[1612] | 101 | |
---|
| 102 | include_once(PHPWG_ROOT_PATH.'include/functions_picture.inc.php'); |
---|
| 103 | $file=''; |
---|
| 104 | switch ($_GET['part']) |
---|
| 105 | { |
---|
| 106 | case 't': |
---|
| 107 | $file = get_thumbnail_path($element_info); |
---|
| 108 | break; |
---|
| 109 | case 'e': |
---|
| 110 | $file = get_element_path($element_info); |
---|
| 111 | break; |
---|
| 112 | case 'i': |
---|
| 113 | $file = get_image_path($element_info); |
---|
| 114 | break; |
---|
| 115 | case 'h': |
---|
[1616] | 116 | if ( $user['enabled_high']!='true' ) |
---|
| 117 | { |
---|
| 118 | do_error(401, 'Access denied h'); |
---|
| 119 | } |
---|
[1612] | 120 | $file = get_high_path($element_info); |
---|
| 121 | break; |
---|
| 122 | } |
---|
| 123 | |
---|
| 124 | if ( empty($file) ) |
---|
| 125 | { |
---|
| 126 | do_error(404, 'Requested file not found'); |
---|
| 127 | } |
---|
| 128 | |
---|
[1817] | 129 | if ($_GET['part'] == 'h') { |
---|
[1844] | 130 | pwg_log($_GET['id'], 'high'); |
---|
[1817] | 131 | } |
---|
[1844] | 132 | else if ($_GET['part'] == 'e') |
---|
| 133 | { |
---|
| 134 | pwg_log($_GET['id'], 'other'); |
---|
| 135 | } |
---|
[1817] | 136 | |
---|
[1612] | 137 | $http_headers = array(); |
---|
| 138 | |
---|
| 139 | $ctype = null; |
---|
| 140 | if (!url_is_remote($file)) |
---|
| 141 | { |
---|
| 142 | if ( !@is_readable($file) ) |
---|
[1560] | 143 | { |
---|
[1612] | 144 | do_error(404, "Requested file not found - $file"); |
---|
[1560] | 145 | } |
---|
[1612] | 146 | $http_headers[] = 'Content-Length: '.@filesize($file); |
---|
| 147 | if ( function_exists('mime_content_type') ) |
---|
[1552] | 148 | { |
---|
[1612] | 149 | $ctype = mime_content_type($file); |
---|
[1552] | 150 | } |
---|
[1616] | 151 | |
---|
| 152 | $gmt_mtime = gmdate('D, d M Y H:i:s', filemtime($file)).' GMT'; |
---|
| 153 | $http_headers[] = 'Last-Modified: '.$gmt_mtime; |
---|
| 154 | |
---|
| 155 | // following lines would indicate how the client should handle the cache |
---|
| 156 | /* $max_age=300; |
---|
| 157 | $http_headers[] = 'Expires: '.gmdate('D, d M Y H:i:s', time()+$max_age).' GMT'; |
---|
| 158 | // HTTP/1.1 only |
---|
| 159 | $http_headers[] = 'Cache-Control: private, must-revalidate, max-age='.$max_age;*/ |
---|
| 160 | |
---|
| 161 | if ( isset( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) |
---|
| 162 | { |
---|
[1643] | 163 | set_status_header(304); |
---|
[1616] | 164 | foreach ($http_headers as $header) |
---|
| 165 | { |
---|
| 166 | header( $header ); |
---|
| 167 | } |
---|
| 168 | exit(); |
---|
| 169 | } |
---|
[1612] | 170 | } |
---|
[1616] | 171 | |
---|
[1612] | 172 | if (!isset($ctype)) |
---|
| 173 | { // give it a guess |
---|
| 174 | $ctype = guess_mime_type( get_extension($file) ); |
---|
| 175 | } |
---|
[1552] | 176 | |
---|
[1612] | 177 | $http_headers[] = 'Content-Type: '.$ctype; |
---|
| 178 | |
---|
| 179 | if (!isset($_GET['view'])) |
---|
| 180 | { |
---|
| 181 | $http_headers[] = 'Content-Disposition: attachment; filename="' |
---|
| 182 | .basename($file).'";'; |
---|
| 183 | $http_headers[] = 'Content-Transfer-Encoding: binary'; |
---|
[985] | 184 | } |
---|
[1616] | 185 | else |
---|
| 186 | { |
---|
| 187 | $http_headers[] = 'Content-Disposition: inline; filename="' |
---|
| 188 | .basename($file).'";'; |
---|
| 189 | } |
---|
[985] | 190 | |
---|
[1612] | 191 | foreach ($http_headers as $header) |
---|
[985] | 192 | { |
---|
[1612] | 193 | header( $header ); |
---|
[985] | 194 | } |
---|
| 195 | |
---|
[1612] | 196 | // Looking at the safe_mode configuration for execution time |
---|
| 197 | if (ini_get('safe_mode') == 0) |
---|
| 198 | { |
---|
| 199 | @set_time_limit(0); |
---|
| 200 | } |
---|
| 201 | |
---|
| 202 | @readfile($file); |
---|
| 203 | |
---|
| 204 | ?> |
---|