Repository navigation
Expand file tree
/
Copy pathserver.php
More file actions
51 lines (42 loc) · 1.32 KB
/
Copy pathserver.php
File metadata and controls
51 lines (42 loc) · 1.32 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
<?php
// This class contains details about the files on the server, directories, etc
class Server
{
/* Used to pull out the list of all the php files in a directory*/
function list_php_files($path){
// to remove any (.) and (..) from the directory list
$files = array_diff(scandir($path), array('.', '..'));
return $files;
}
/* Used to pull out the list of all the files and folders in a directory*/
function list_all_files($path) {
$files = scandir($path);
print_r($files);
}
/* Generate time ago using the given timestamp */
static function time_elapsed_string($datetime, $full = false) {
$now = new DateTime;
$ago = new DateTime($datetime);
$diff = $now->diff($ago);
$diff->w = floor($diff->d / 7);
$diff->d -= $diff->w * 7;
$string = array(
'y' => 'year',
'm' => 'month',
'w' => 'week',
'd' => 'day',
'h' => 'hour',
'i' => 'minute',
's' => 'second',
);
foreach ($string as $k => &$v) {
if ($diff->$k) {
$v = $diff->$k . ' ' . $v . ($diff->$k > 1 ? 's' : '');
} else {
unset($string[$k]);
}
}
if (!$full) $string = array_slice($string, 0, 1);
return $string ? implode(', ', $string) . ' ago' : 'just now';
}
}