From de56ccca07e19c5163792c210ff5f6130e91d892 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 28 May 2008 10:03:21 -0400 Subject: [PATCH] add timestamp to avatar filenames to prevent overlap darcs-hash:20080528140321-84dde-2dbeb6032e845a23bb1adde1cbc1788333b55156.gz --- actions/avatar.php | 6 +++--- lib/util.php | 10 +++++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/actions/avatar.php b/actions/avatar.php index 81eb23cec0..023a8414a1 100644 --- a/actions/avatar.php +++ b/actions/avatar.php @@ -108,7 +108,7 @@ class AvatarAction extends SettingsAction { $user = common_current_user(); - $filename = common_avatar_filename($user, image_type_to_extension($info[2])); + $filename = common_avatar_filename($user, image_type_to_extension($info[2]), NULL, common_timestamp()); $filepath = common_avatar_path($filename); if (!move_uploaded_file($_FILES['avatarfile']['tmp_name'], $filepath)) { @@ -166,9 +166,9 @@ class AvatarAction extends SettingsAction { imagecopyresampled($image_s, $image_a, 0, 0, 0, 0, $size, $size, $square, $square); - $ext = ($avatar->mediattype == 'image/jpeg') ? ".jpg" : ".png"; + $ext = ($avatar->mediattype == 'image/jpeg') ? ".jpeg" : ".png"; - $filename = common_avatar_filename($user, $ext, $size); + $filename = common_avatar_filename($user, $ext, $size, common_timestamp()); if ($avatar->mediatype == 'image/jpeg') { imagejpeg($image_s, common_avatar_path($filename)); diff --git a/lib/util.php b/lib/util.php index 52f25c9d3c..9c288198cb 100644 --- a/lib/util.php +++ b/lib/util.php @@ -349,13 +349,13 @@ function common_render_content($text) { // where should the avatar go for this user? -function common_avatar_filename($user, $extension, $size=NULL) { +function common_avatar_filename($user, $extension, $size=NULL, $extra=NULL) { global $config; if ($size) { - return $user->id . '-' . $size . $extension; + return $user->id . '-' . $size . (($extra) ? $extra : '') . $extension; } else { - return $user->id . '-original' . $extension; + return $user->id . '-original' . (($extra) ? $extra : '') . $extension; } } @@ -479,6 +479,10 @@ function common_mtrand($bytes) { return $enc; } +function common_timestamp() { + return date('YmdHisu'); +} + // XXX: set up gettext function _t($str) {