-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFSfile.php
More file actions
executable file
·79 lines (74 loc) · 3.96 KB
/
FSfile.php
File metadata and controls
executable file
·79 lines (74 loc) · 3.96 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
/****************** DO NOT REMOVE OR ALTER THIS HEADER ******************************
* *
* Product: FSnode *
* FSnode is a node-based Uniform FileSystem handler, written in PHP. It allows *
* you to access all kind of file systems in the exact same manner, with the same *
* simple commands. You can write your web application once and let users switch *
* file system/platform; mount through URI. *
* *
* Latest version to download: *
* https://github.com/sentfanwyaerda/FSnode *
* *
* Documentation: *
* http://sent.wyaerda.org/FSnode/ *
* https://github.com/sentfanwyaerda/FSnode/blob/master/manual/Introduction.md *
* *
* Authors: *
* Sent fan Wyærda (fsnode@sent.wyaerda.org) [creator, main] *
* *
* License: cc-by-nd *
* Creative Commons, Attribution-No Derivative Works 3.0 Unported *
* http://creativecommons.org/licenses/by-nd/3.0/ *
* http://creativecommons.org/licenses/by-nd/3.0/legalcode *
* *
****************** CHANGES IN THE CODE ARE AT OWN RISK *****************************/
require_once(dirname(__FILE__).DIRECTORY_SEPARATOR.'FSnode.php');
class FSfile extends Xnode {
public function Version($f=FALSE){ return FSnode::Version($f); }
public function Product_url($u=FALSE){ return FSnode::Product_url($u); }
public function Product($full=FALSE){ return FSnode::Product($full); }
public function License($with_link=FALSE){ return FSnode::License($with_link); }
public function License_url(){ return FSnode::License_url(); }
public function Product_base(){ return dirname(__FILE__).DIRECTORY_SEPARATOR; }
public function Product_file($full=FALSE){ return ($full ? self::Product_base() : NULL).basename(__FILE__); }
var /*mounted FSnode|FSarchive*/ $fsnode;
var $URI;
private $_reference;
function FSfile($URI, &$fsnode){
$this->URI = $URI;
if(!isset($fsnode) || !is_object($fsnode)){ $fsnode = FSnode($URI); }
$this->fsnode &= $fsnode;
$this->open();
}
public /*string*/ function __toString(){ return (string) $this->read(); }
public /*string*/ function read($ignore=TRUE){
#if(){ $this->open(); }
$data = file_get_contents($this->_reference);
return $data;
}
public function write($ignore=TRUE, $data=NULL, $auto_save=FALSE){
$status = file_put_contents($this->_reference, $data);
if(!($auto_save===FALSE)){ $this->save(); }
return $status;
}
public /*dummy*/ function connect($URI=NULL, $refresh=FALSE){ return $this->open($URI, $refresh); }
public function open($URI=NULL, $refresh=FALSE){
#if($refresh === TRUE && !file_exists($this->_reference))
$this->_reference = tempname();
$data = $this->fsnode->read($this->URI);
if(!($data === FALSE) && strlen($data) > 0){ $this->write($data); return TRUE; }
else{ return FALSE; }
}
public function save($as=FALSE){
if($as===FALSE){ $as = $this->URI; }
return $this->fsnode->write($as, $this->read());
}
public function close(){
#clean-up: remove file $this->_reference;
unlink($this->_reference);
$this->_reference = NULL;
#destroy $this
}
}
?>