-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpicture.php
More file actions
207 lines (193 loc) · 5.33 KB
/
picture.php
File metadata and controls
207 lines (193 loc) · 5.33 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
<?php
set_time_limit(0);
//获取源目录
//$Path = $_GET['Path'];
//获取卡牌ID
$cardId = intval($_GET['cardId']);
if($cardId < 10000)
{
exit("error cardId!");
}
//获取类型
$imgType = $_GET['imgType'];
if($imgType != 'card' && $imgType != 'face')
{
exit("require error!");
}
//获取版本ver
$ver = $_GET['ver'];
if(!$ver)
{
exit("ver null!");
}
//获取版本ver
$Type = $_GET['type'];
if($Type != 'unit' && $Type != 'monster')
{
exit("error type!");
}
//获取相对目录
//switch($imgType){
// case 'face':$newPath = "Face/Unit";break;
// case 'card':$newPath = "Card/Large";break;
//}
getImage($cardId,$imgType,$ver,$Type);
function getImage($cardId,$imgType,$ver,$Type,$type = false){
switch($ver){
case 'cn':
$www_path .= '/www/qa.fanta.91dena.com/CN/fanta_cn_sandbox';
$ServerUrl = "http://cnqa.fanta.91dena.com/CN/android/Data/Chara/";//QA服务器资源链接
$NewCardPath = "/www/qa.fanta.91dena.com/CN/android/Data/Chara/";//QA服务器资源路径
break;
case 'cn2':
$www_path .= '/www/qa.fanta.91dena.com/CN/fanta_cn2_sandbox';
$ServerUrl = "http://cnqa.fanta.91dena.com/CN/android/Data/Chara/";//QA服务器资源链接
$NewCardPath = "/www/qa.fanta.91dena.com/CN/android/Data/Chara/";//QA服务器资源路径
break;
/*case 'cht':
$www_path = '/www/fanta.91dena.com/fanta_tw_sandbox';
$ServerUrl = "http://twqa.fanta.91dena.com";
break;
case 'kr':
$www_path .= 'KR/fanta_kr_sandbox';
break;*/
default:
exit('error parameters ver');
}
require_once($www_path."/config/config.inc");
require_once($www_path."/config/Stage/config.inc");
$Path = RESOURCE_ANDROID_URL."android/Data/Chara/";//资源更新服务器路径
//检查cardId是否存在
require_once($www_path.'/data/Unit/UnitData_cn.php');
require_once($www_path.'/data/Unit/Monster_cn.php');
if($cardId >= 10000 && $cardId < 20000){
if(!array_key_exists($cardId, $UnitData)){
exit("该卡牌不存在!");
}
}elseif($cardId > 20000) {
if(!array_key_exists($cardId, $MonsterData)){
exit("该卡牌不存在!");
}
}
//图片后缀格式
switch($Type){
case 'unit':
switch($imgType){
case 'face':$center = "Face/Unit/";$Format = "u".$cardId."_f.png";break;
case 'card':$center = "Card/Large/";$Format = "u".$cardId."_c.jpg";break;
}
break;
case 'monster':
switch($imgType){
case 'face':$center = "Face/Enemy/";$Format = "m".$cardId."_f.png";break;
case 'card':$center = "Enemy/Large/";$Format = "m".$cardId."_c.jpg";break;
}
break;
}
//创建目录并修改权限
readFileFromDir($NewCardPath.$center);
$flg = $NewCardPath.$center.$Format;
$filemtime = filemtime($flg);
//header('Last-Modified: '.$filemtime);
if(!file_exists($flg) || $imgType != 'face')
{
//**********文件比较是否更新**************
$url = $Path.$center.$Format;
$url2 = $NewCardPath.$center.$Format;
//$start_time = time();
$headInf = get_headers($url,1);
//$end_time = time();
//echo "CARD:{$cardname} ".($end_time - $start_time)."s<BR>";
$file = strtotime($headInf['Last-Modified']);
$file2 = filectime($url2);
if ($file > $file2)
{
//下载图片
if($type){
$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$file = curl_exec($ch);
curl_close($ch);
}else{
//ob_start();
//readfile($url);
//$file = ob_get_contents();
//ob_end_clean();
$opts = array(
'http'=>array(
'method'=>"GET",
'timeout'=>6,
)
);
$context = stream_context_create($opts);
$file = file_get_contents($url,false,$context);
if(!$file){
return ;
}
}
//保存文件
$res = fopen($NewCardPath.$center.$Format,'w');
if(!chmod($NewCardPath.$center.$Format,0777)){
exit('change fail');
}
if (!fwrite($res,$file)){
exit('write error');
}
fclose($res);
//设置缓存文件时间
$flg = $NewCardPath.$center.$Format;
$filemtime = filemtime($flg);
header('Last-Modified: '.$filemtime);
//exit($flg);
header('Content-Type: image/jpeg');
echo file_get_contents($ServerUrl.$center.$Format);
}else{
$lastmodtime = $_SERVER["HTTP_IF_MODIFIED_SINCE"];
if($filemtime <= $lastmodtime){
header('HTTP/1.1 304 Not Modified');
exit;
}else{
header('Last-Modified: '.$filemtime);
//exit($ServerUrl.$center.$Format);
header('Content-Type: image/jpeg');
echo file_get_contents($ServerUrl.$center.$Format);
}
}
//**********文件比较是否更新**************
}else{
$lastmodtime = $_SERVER["HTTP_IF_MODIFIED_SINCE"];
if($filemtime <= $lastmodtime){
header('HTTP/1.1 304 Not Modified');
exit;
}else{
header('Last-Modified: '.$filemtime);
//exit($ServerUrl.$center.$Format);
header('Content-Type: image/jpeg');
echo file_get_contents($ServerUrl.$center.$Format);
}
}
}
//递归创建文件夹和修改权限
function readFileFromDir($dir)
{
if(!is_dir($dir))
{
if(!readFileFromDir(dirname($dir)))
{
return false;
}
if(!mkdir($dir))
{
return false;
}
if(!chmod($dir,0777))
{
return false;
}
}
return true;
}
?>