forked from zyx0814/dzzoffice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
avatar.php
55 lines (49 loc) · 1.74 KB
/
avatar.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
/*
* @copyright Leyun internet Technology(Shanghai)Co.,Ltd
* @license http://www.dzzoffice.com/licenses/license.txt
* @package DzzOffice
* @link http://www.dzzoffice.com
* @author zyx([email protected])
*/
error_reporting(0);
define('SITEURL', strtolower(($_SERVER['HTTPS'] == 'on' ? 'https' : 'http').'://'.$_SERVER['HTTP_HOST'].substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['PHP_SELF'], '/'))));
$uid = isset($_GET['uid']) ? $_GET['uid'] : 0;
$size = isset($_GET['size']) ? $_GET['size'] : '';
$random = isset($_GET['random']) ? $_GET['random'] : '';
$type = isset($_GET['type']) ? $_GET['type'] : '';
$check = isset($_GET['check_file_exists']) ? $_GET['check_file_exists'] : '';
$avatar = './data/avatar/'.get_avatar($uid, $size, $type);
if(file_exists(dirname(__FILE__).'/'.$avatar)) {
if($check) {
echo 1;
exit;
}
$random = !empty($random) ? rand(1000, 9999) : '';
$avatar_url = empty($random) ? $avatar : $avatar.'?random='.$random;
} else {
if($check) {
echo 0;
exit;
}
$size = in_array($size, array('big', 'middle', 'small')) ? $size : 'middle';
$avatar_url = 'static/image/avatar/noavatar_'.$size.'.gif';
}
if(empty($random)) {
header("HTTP/1.1 301 Moved Permanently");
header("Last-Modified:".date('r'));
header("Expires: ".date('r', time() + 86400));
}
header('Location: '.SITEURL.'/'.$avatar_url);
exit;
function get_avatar($uid, $size = 'middle', $type = '') {
$size = in_array($size, array('big', 'middle', 'small')) ? $size : 'middle';
$uid = abs(intval($uid));
$uid = sprintf("%09d", $uid);
$dir1 = substr($uid, 0, 3);
$dir2 = substr($uid, 3, 2);
$dir3 = substr($uid, 5, 2);
$typeadd = $type == 'real' ? '_real' : '';
return $dir1.'/'.$dir2.'/'.$dir3.'/'.substr($uid, -2).$typeadd."_avatar_$size.jpg";
}
?>