aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/download
diff options
context:
space:
mode:
authorHenry Sudhof <kellanved@phpbb.com>2007-11-16 14:21:05 +0000
committerHenry Sudhof <kellanved@phpbb.com>2007-11-16 14:21:05 +0000
commit053730e47727c5d91ba1a3a96196ab5802dedc5a (patch)
tree8e50bc0eff6be9fb986103f24de049132f1f9b24 /phpBB/download
parentbec8f7b22cb754910df886603e80da5ff421d3ad (diff)
downloadforums-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
Diffstat (limited to 'phpBB/download')
-rw-r--r--phpBB/download/file.php34
1 files changed, 25 insertions, 9 deletions
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');