-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFileWriting_old.php
67 lines (61 loc) · 1.4 KB
/
FileWriting_old.php
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
64
65
66
67
<?php
namespace JW3B\Data;
use JW3B\erday\Helpful_Files;
class FileWriting {
public static $dir_path = __DIR__.'/../../cache/';
public static function save($path, $data){
$dirs = explode('/', $path);
$total = count($dirs);
$fileName = $dirs[$total - 1];
if($total > 1){
for($i=0;$i<$total;$i++){
if($dirs[$i] != $fileName){
Helpful_Files::mk_dir_writable(self::$dir_path . $path.$dirs[$i]);
}
}
}
$fp = fopen(self::$dir_path . $path.'.dat', 'w');
flock($fp, 2);
fwrite($fp, self::file_data($data));
flock($fp, 3);
fclose($fp);
}
public static function file_data($str){
if(is_array($str)){
return implode('|', $str);
} else {
return $str;
}
}
public static function check($path, $key){
if(is_file(self::$dir_path . $path)){
$file = file(self::$dir_path . $path);
$rows = explode("\n", $file);
foreach($rows as $r => $rr){
$cols = explode('|', trim( $rr ));
if(trim( $cols[0] ) == $key){
return ($r+1);
}
}
return false;
} else {
return false;
}
}
public static function remove($path, $key){
if(is_file(self::$dir_path . $path)){
$file = file(self::$dir_path . $path);
$rows = explode("\n", $file);
$put_back_in = '';
foreach($rows as $rr){
$cols = explode('|', trim( $rr ));
if(trim( $cols[0] ) != $key){
$put_back_in = trim($rr)."\n";
}
}
return false;
} else {
return false;
}
}
}