-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_img_path.php
70 lines (68 loc) · 1.42 KB
/
get_img_path.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
<?php
/**
* Created by PhpStorm.
* User: weiyixi
* Date: 2020/2/1
* Time: 6:59 PM
*/
$menuId = isset($_GET['menuId'])?$_GET['menuId']:'menu01';
$path = __DIR__."/static/img/$menuId";
$file=$path;
// 扫描$con目录下的所有文件
$filename = scandir($file);
// 定义一个数组接收文件名
$conname = array();
foreach($filename as $k=>$v){
// 跳过两个特殊目录 continue跳出循环
if($v=="." || $v==".."){continue;}
//截取文件名,我只需要文件名不需要后缀;然后存入数组。如果你是需要后缀直接$v即可strpos($v,".")
$conname[] = substr(substr($v,0,strpos($v,".")),strrpos($v,'_')+1);
}
$data = [];
//var_dump($conname);
$conname = array_unique($conname);
foreach ($conname as $item){
if(strlen($item)<2){
continue;
}
$data[]=['picId'=>$menuId.'_'.$item.'.jpg','size'=>'1500*1000'];
$data[]=['picId'=>'mini_'.$menuId.'_'.$item.'.jpg','size'=>'225*150'];
}
$a = ob_get_clean();
echo json_encode(['status'=>'ok','msg'=>'success','data'=>$data]);die;
/**
{
"status":"ok",
"msg":"success",
"data":[
{
"picId":"menu01_028.jpg",
"size":"1500*1000"
},
{
"picId":"menu01_045.jpg",
"size":"1500*1000"
},
{
"picId":"mini_menu01_009.jpg",
"size":"225*150"
},
{
"picId":"mini_menu01_043.jpg",
"size":"150*100"
},
{
"picId":"mini_menu01_026.jpg",
"size":"225*150"
},
{
"picId":"menu01_046.jpg",
"size":"1500*834"
},
{
"picId":"mini_menu01_014.jpg",
"size":"225*150"
}
]
}
*/