forked from whcyc2002/swoole_framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_css_image.php
More file actions
60 lines (56 loc) · 1.39 KB
/
get_css_image.php
File metadata and controls
60 lines (56 loc) · 1.39 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
<?php
if($argc < 5)
{
echo "php ".basename(__FILE__)," css文件目录 远程URL 目标文件夹 目标本地路径\n";exit;
}
$dir = $argv[1];
$remote = $argv[2];
$dest = $argv[3];
$csspath = $argv[4];
$files = scandir($dir);
foreach($files as $f)
{
if(substr($f, -4, 4)=='.css')
{
parseCssFile($dir.'/'.$f);
}
}
function parseCssFile($f)
{
global $remote, $dest, $csspath;
$patten = '#url\s*\(\s*(.*)\s*\)#';
$content = file_get_contents($f);
$match = array();
$n = preg_match_all($patten, $content, $match);
if($n > 0)
{
foreach($match[1] as $_m)
{
$m = trim($_m, "'\" \r\n");
if($m[0]!='/') $m = '/'.$m;
$_fd = $dest.$m;
$_fs = $remote.$m;
if(!is_dir(dirname($_fd)))
{
mkdir(dirname($_fd), 0777, true);
}
if(is_file($_fd))
{
echo "file exists.[$_fd]\n";
continue;
}
str_replace($m, $csspath.$m, $content);
if(copy($_fs, $_fd))
{
echo "download remote file[$_fs] to [$_fd].\n";
//var_dump($m, $csspath.$m);
}
else
{
echo "download fail.file[$_fs] to [$_fd].\n";
}
}
}
file_put_contents($f, $content);
echo "parse ok. [$f]\n";
}