-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGetPic.class.php
70 lines (65 loc) · 2.31 KB
/
GetPic.class.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
class GetPic {
// property
// public $name;
// constructor
public $serial_id;
public $device;
public function __construct($serial_id) {
// $this->name = $name;
$this->serial_id = $serial_id;
$this->serial_id_path = dirname(__FILE__).'/uploads/'.$this->serial_id;
# $this->device = $device;
# $this->device_path = $this->serial_id_path.'/'.$this->device;
}
public function get_latest_ymd_subfolder($directory_path){
$f = scandir($directory_path);
$ff = preg_grep("/^[0-9]{8}$/", $f); # 20160718 and so on.
rsort($ff, SORT_STRING);
return $ff[0];
}
public function get_latest_pic_on_the_folder($directory_path){
$f = scandir($directory_path);
$ff = preg_grep("/^[0-9]{14}.jpeg/", $f); # 20160718 and so on.
rsort($ff, SORT_STRING);
return $ff[0];
}
public function get_latest_pic($device){
# device_path の作成
if ($device == ""){
$this->device = "";
$this->device_path = "";
} else {
$this->device = $device;
$this->device_path = $this->serial_id_path.'/'.$device;
}
# 設定の読み込み
$configfile = "uploads/".$this->serial_id."/SavePic.ini";
$ini = parse_ini_file($configfile);
# 戻り値
$result_array = array('serial_id' => $this->serial_id, 'device' => $this->device);
switch ($ini["folder_type"]){
case "device":
$result_array['ymd'] = '';
$result_array['pic_file_name'] = $this->get_latest_pic_on_the_folder($this->device_path);
break;
case "device_date":
$result_array['ymd'] = $this->get_latest_ymd_subfolder($this->device_path);
$result_array['pic_file_name'] = $this->get_latest_pic_on_the_folder($this->device_path.'/'.$result_array['ymd']);
break;
case "serial_id":
$result_array['device'] = '';
$result_array['ymd'] = '';
$result_array['pic_file_name'] = $this->get_latest_pic_on_the_folder($this->serial_id_path);
break;
case "serial_id_date":
$result_array['device'] = '';
$result_array['ymd'] = $this->get_latest_ymd_subfolder($this->serial_id_path);
$result_array['pic_file_name'] = $this->get_latest_pic_on_the_folder($this->serial_id_path.'/'.$result_array['ymd']);
break;
default:
break;
}
return $result_array;
}
}