class_mcFile.inc.php
1.36 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
52
53
54
55
56
57
58
59
60
61
62
63
<?
class mcFile {
/**
*
*
* @param string $param_filename
* @param string $param_text
* @param string $param_kindof -- r|r+|w|w+|a|a+ @see http://de3.php.net/manual/de/function.fopen.php
* r - ptr at the beginning
* w - ptr at the beginning and file size 0
* a - ptr at the end
* @return bool
*/
public static function write($param_filename, $param_text, $param_kindof = null) {
if($param_filename && $param_text) {
if($param_kindof === null) {
$param_kindof = 'a';
}
try {
@$var_file = fopen($param_filename,$param_kindof);
if ($var_file === false) {
return false;
} else {
fputs($var_file, $param_text);
fputs($var_file, mcCONST::LINEBREAK.mcCONST::LINEBREAK);
}
fclose($var_file);
return true;
} catch (Exception $e) {
mcException::handleException($e);
}
} else {
return false;
}
}
public static function getFileContent($param_filename) {
if(is_readable($param_filename)) {
try {
$handle = fopen ($param_filename, "r");
$array_content = array();
while (!feof($handle)) {
$array_content[] = fgets($handle);
}
fclose ($handle);
return $array_content;
} catch (Exception $e) {
mcException::handleException($e);
return false;
}
} else {
return Error::newError('DevError', 'file could not read', $param_code);
}
}
}
?>