-
-
Notifications
You must be signed in to change notification settings - Fork 173
Expand file tree
/
Copy pathphp_file_utilities.php
More file actions
50 lines (41 loc) · 1.25 KB
/
Copy pathphp_file_utilities.php
File metadata and controls
50 lines (41 loc) · 1.25 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
<?php
if (!defined('PHP_TEXT_CACHE_INCLUDE_PATH')) {
define('PHP_TEXT_CACHE_INCLUDE_PATH', (dirname(__FILE__) . "/"));
}
class php_file_utilities {
/**
* Retrieves binary or text data from the specified file
* @param string The file path
* @param string The attributes for the read operation ('r' or 'rb' or 'rt')
* @return mixed he text or binary data contained in the file
*/
function &getDataFromFile($filename, $readAttributes, $readSize = 8192) {
$fileContents = null;
$fileHandle = @fopen($filename, $readAttributes);
if($fileHandle){
do {
$data = fread($fileHandle, $readSize);
if (strlen($data) == 0) {
break;
}
$fileContents .= $data;
} while (true);
fclose($fileHandle);
}
return $fileContents;
} //getDataFromFile
/**
* Writes the specified binary or text data to a file
* @param string The file path
* @param mixed The data to be written
* @param string The attributes for the write operation ('w' or 'wb')
*/
function putDataToFile($fileName, &$data, $writeAttributes) {
$fileHandle = @fopen($fileName, $writeAttributes);
if ($fileHandle) {
fwrite($fileHandle, $data);
fclose($fileHandle);
}
} //putDataToFile
} //php_file_utilities
?>