JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
upload.php cleanup: really don't make dot files
[wfpl.git] / file.php
1 <?php
2
3 # This program is in the public domain within the United States. Additionally,
4 # we waive copyright and related rights in the work worldwide through the CC0
5 # 1.0 Universal public domain dedication, which can be found at
6 # http://creativecommons.org/publicdomain/zero/1.0/
7
8
9 # This exists because file_get_contents() is not documented well. (It says that
10 # the second parameter is optional, but does not specify the default behavior.)
11 function read_whole_file($name) {
12         $fd = fopen($name, 'r');
13         if($fd === false) {
14                 die("Failed to read file: '$name'");
15         }
16         $file_data = fread($fd, filesize($name));
17         fclose($fd);
18         return $file_data;
19 }
20
21 # This exists because file_put_contents() is not included in PHP4.
22 function write_whole_file($name, $data) {
23         $fd = fopen($name, 'w');
24         if($fd === false) {
25                 die("Failed to read file: '$name'");
26         }
27         fwrite($fd, $data);
28         fclose($fd);
29 }
30
31 function read_whole_file_or_false($name) {
32         if(!file_exists($name)) {
33                 return false;
34         }
35         return read_whole_file($name);
36 }
37
38 ?>