-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction.php
More file actions
57 lines (55 loc) · 1.87 KB
/
function.php
File metadata and controls
57 lines (55 loc) · 1.87 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
<?php
function readFromConsole($input){
if ($input === '!stop'){
return null;
}
else if($input === 'true'){
$input = true;
}
else if($input === 'false'){
$input = false;
}
else if(is_numeric($input)){
$input = +$input;
}
else{
$input = (string)$input;
}
return $input;
}
function getDirectionStatus($input){
echo "Функция вывода статусов файлов в директории".PHP_EOL."Введенная директория: {$input}".PHP_EOL;
$cur_dir = 0;
$cur_file = 0;
$list = ['dirs' => [$cur_dir => ['is_read' => [], 'is_write' => []]],
'files' => [$cur_file => ['is_read' => [],'is_write' => [],'size' => []]]];
$dir = opendir($input);
while($elem = readdir($dir))
{
$correct_path = $input.$elem;//вычисление правильного пути до файла или директории
if (in_array($elem, ['.','..']))
{
continue;
}
if (is_dir($correct_path))
{
is_readable($correct_path) ? $list['dirs'][$elem]['is_read'] = true:
$list['dirs'][$elem]['is_read'] = false;
is_writable($correct_path) ? $list['dirs'][$elem]['is_write'] = true:
$list['dirs'][$elem]['is_write'] = false;
}
else if (is_file($correct_path))
{
is_readable($correct_path) ? $list['files'][$elem]['is_read'] = true:
$list['files'][$elem]['is_read'] = false;
is_writable($correct_path) ? $list['files'][$elem]['is_write'] = true:
$list['files'][$elem]['is_write'] = false;
$list['files'][$elem]['size'] = filesize($correct_path);
}
}
closedir($dir);
unset($list['dirs'][0]);
unset($list['files'][0]);
var_export($list);
echo PHP_EOL;
}