-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile.php
More file actions
40 lines (36 loc) · 812 Bytes
/
file.php
File metadata and controls
40 lines (36 loc) · 812 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
35
36
37
38
39
40
<?php
require_once(dirname(__FILE__) . "/errors.php");
function file_load($filename) {
if(is_array($f = @file($filename))) {
return join('', $f);
} else {
error("Could not read file $filename");
return E_SERVFAIL;
}
}
function file_store($filename, $data) {
if ($f = fopen($filename, "a+")) {
if(flock($f, LOCK_EX)) {
if(ftruncate($f, 0)) {
if(fwrite($f, $data, strlen($data))) {
flock($f, LOCK_UN);
fclose($f);
return E_SUCCESS;
} else {
error('Could not write file');
return E_SERVFAIL;
}
} else {
error('Could not truncate file');
return E_SERVFAIL;
}
} else {
error('Could not lock file');
return E_SERVFAIL;
}
} else {
error('Could not open file for writing');
return E_SERVFAIL;
}
}
?>