-
Notifications
You must be signed in to change notification settings - Fork 626
Expand file tree
/
Copy pathfile.inc
More file actions
34 lines (27 loc) · 762 Bytes
/
file.inc
File metadata and controls
34 lines (27 loc) · 762 Bytes
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
<?php
/*
* This file contains helper functions to deal with files in a safe manner.
* These functions check for file existence and readability before performing
* any operations on them.
*/
function file_get_size(string $filename): int|false
{
if (!file_exists($filename) || !is_readable($filename)) {
return false;
}
return filesize($filename);
}
function file_get_mtime(string $filename): int|false
{
if (!file_exists($filename) || !is_readable($filename)) {
return false;
}
return filemtime($filename);
}
function file_get_contents_if_exists(string $filename): string|false
{
if (!file_exists($filename) || !is_readable($filename)) {
return false;
}
return file_get_contents($filename);
}