diff options
author | Henry Sudhof <kellanved@phpbb.com> | 2007-11-16 14:21:05 +0000 |
---|---|---|
committer | Henry Sudhof <kellanved@phpbb.com> | 2007-11-16 14:21:05 +0000 |
commit | 053730e47727c5d91ba1a3a96196ab5802dedc5a (patch) | |
tree | 8e50bc0eff6be9fb986103f24de049132f1f9b24 | |
parent | bec8f7b22cb754910df886603e80da5ff421d3ad (diff) | |
download | forums-053730e47727c5d91ba1a3a96196ab5802dedc5a.tar forums-053730e47727c5d91ba1a3a96196ab5802dedc5a.tar.gz forums-053730e47727c5d91ba1a3a96196ab5802dedc5a.tar.bz2 forums-053730e47727c5d91ba1a3a96196ab5802dedc5a.tar.xz forums-053730e47727c5d91ba1a3a96196ab5802dedc5a.zip |
Nothing we can do about IE 6, but this should reduce the bandwidth need significantly.
git-svn-id: file:///svn/phpbb/trunk@8238 89ea8834-ac86-4346-8a33-228a782c2dd0
-rw-r--r-- | phpBB/docs/CHANGELOG.html | 2 | ||||
-rw-r--r-- | phpBB/download/file.php | 34 |
2 files changed, 27 insertions, 9 deletions
diff --git a/phpBB/docs/CHANGELOG.html b/phpBB/docs/CHANGELOG.html index 342de3ed6f..08a9f1c9cd 100644 --- a/phpBB/docs/CHANGELOG.html +++ b/phpBB/docs/CHANGELOG.html @@ -101,6 +101,8 @@ <li>[Fix] Use correct RFC 2822 date format in emails (Bug #15042)</li> <li>[Fix] Require founder status for some actions on founder-only groups (Bug #15119)</li> <li>[Fix] Allow changing the "now" option of date CPFs (Bug #15111)</li> + <li>[Change] Some improvements to the caching of avatars</li> + </ul> <a name="v30rc6"></a><h3>1.ii. Changes since 3.0.RC6</h3> diff --git a/phpBB/download/file.php b/phpBB/download/file.php index 0cc5b1465b..0b4e0116db 100644 --- a/phpBB/download/file.php +++ b/phpBB/download/file.php @@ -32,6 +32,9 @@ if (isset($_GET['avatar'])) exit; } unset($dbpasswd); + + // worst-case default + $browser = (!empty($_SERVER['HTTP_USER_AGENT'])) ? htmlspecialchars((string) $_SERVER['HTTP_USER_AGENT']) : 'msie 6.0'; $config = $cache->obtain_config(); $filename = $_GET['avatar']; @@ -53,9 +56,25 @@ if (isset($_GET['avatar'])) $db->sql_close(); exit; } - + $ext = substr(strrchr($filename, '.'), 1); - $filename = intval($filename); + $stamp = (int) substr(stristr($filename, '_'), 1); + $filename = (int) $filename; + + // let's see if we have to send the file at all + $last_load = isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? strtotime(trim($_SERVER['HTTP_IF_MODIFIED_SINCE'])) : false; + if (strpos(strtolower($browser), 'msie 6.0') === false) + { + if ($last_load !== false && $last_load <= $stamp) + { + header('Not Modified', true, 304); + exit(); + } + else + { + header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $stamp) . ' GMT'); + } + } if (!in_array($ext, array('png', 'gif', 'jpg', 'jpeg'))) { @@ -68,7 +87,7 @@ if (isset($_GET['avatar'])) $db->sql_close(); exit; } - + if (!$filename) { // no way such an avatar could exist. They are not following the rules, stop the show. @@ -81,7 +100,7 @@ if (isset($_GET['avatar'])) exit; } - send_avatar_to_browser(($avatar_group ? 'g' : '') . $filename . '.' . $ext); + send_avatar_to_browser(($avatar_group ? 'g' : '') . $filename . '.' . $ext, $browser); if (!empty($cache)) { @@ -267,16 +286,13 @@ else * A simplified function to deliver avatars * The argument needs to be checked before calling this function. */ -function send_avatar_to_browser($file) +function send_avatar_to_browser($file, $browser) { global $config, $phpbb_root_path; $prefix = $config['avatar_salt'] . '_'; $image_dir = $config['avatar_path']; - // worst-case default - $browser = (!empty($_SERVER['HTTP_USER_AGENT'])) ? htmlspecialchars((string) $_SERVER['HTTP_USER_AGENT']) : 'msie 6.0'; - // Adjust image_dir path (no trailing slash) if (substr($image_dir, -1, 1) == '/' || substr($image_dir, -1, 1) == '\\') { @@ -290,7 +306,7 @@ function send_avatar_to_browser($file) } $file_path = $phpbb_root_path . $image_dir . '/' . $prefix . $file; - if ((@file_exists($file_path) && @is_readable($file_path)) || headers_sent()) + if ((@file_exists($file_path) && @is_readable($file_path)) && !headers_sent()) { header('Pragma: public'); |