-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathcb.php
100 lines (84 loc) · 1.96 KB
/
cb.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
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
<?php
//抓取文件
function get_contents($url){
$ch =curl_init($url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$str =curl_exec($ch);
curl_close($ch);
if ($str !==false) {
return $str;
}else {
return '';
}
}
//得到扩展名
function get_extend($file_name) {
$extend =explode("." , $file_name);
$va=count($extend)-1;
return $extend[$va];
}
/**
* begin
*/
//cdn上存在的各种可能的文件类型
$header = array(
'js' => 'Content-Type: application/x-javascript',
'css' => 'Content-Type: text/css',
'jpg' => 'Content-Type: image/jpg',
'gif' => 'Content-Type: image/gif',
'png' => 'Content-Type: image/png',
'jpeg' => 'Content-Type: image/jpeg',
'swf' => 'Content-Type: application/x-shockwave-flash'
);
//文件类型
$type = '';
//文件完整路径数组
$files = array();
//前缀
$prefix = $_SERVER['SCRIPT_NAME'];
$split_a= explode("??",$_SERVER['REQUEST_URI']);
//echo join("\n",$split_a);
//echo "\n****************\n";
$split_a[1] = preg_replace("/\\?.*$/",
"",
$split_a[1]);
//echo $prefix;
//echo "\n****************\n";
//echo join("\n",$split_a);
//echo "\n****************\n";
if(preg_match('/,/',$split_a[1])){//多文件
$_tmp = explode(',',$split_a[1]);
foreach($_tmp as $v){
$files[] = $prefix.$v;
}
}else{//单文件
$files[] = $prefix.$split_a[1];
}
$R_files = array();
foreach ($files as $k) {
$k = preg_replace(
array('/^\//'),
array(''),
$k);
if(!preg_match('/(\.js|\.css)$/',$k)){
continue;
}
if(empty($type)) {
$type = get_extend($k);
}
//echo $k."\n";
//文件存在
if(file_exists($k)) {
$R_files[] = file_get_contents($k);
}
}
//添加过期头
//header("Expires: " . date("D, j M Y H:i:s", strtotime("now + 10 years")) ." GMT");
//文件类型
header($header[$type]);
//拼装文件
$result = join("\n",$R_files);
//输出文件
echo $result;
?>