5 class Files extends \Rsi\Fred\Component{
18 return $this->_root && $this->_user->id && preg_match(
'/^(\\w+\\/)*\\w+(\\.\\w+)?$/',$filename)
19 ? $this->_root . $this->_user->id .
'/' . $filename
27 public function list($types = null){
29 $filters = [\Rsi\File::FIND_FILTER_SIZE .
'>' => 0,\Rsi\File::FIND_FILTER_TIME .
'>' => 0];
30 if($types) $filters[\Rsi\File::FIND_FILTER_NAME .
'//'] = is_array($types) ?
'/\\.(' . implode(
'|',$types) .
')$/i' : $types;
31 if($this->_root && $this->_user->id && ($files = \
Rsi\File::find($root = $this->_root . $this->_user->id,$filters,
true))){
32 $root = strlen($root) + 1;
33 foreach($files as $filename => $info) $result[str_replace(DIRECTORY_SEPARATOR,
'/',substr($filename,$root))] = $info;
43 foreach($this->
list() as $info) $total += $info[
'size'];
52 public function save($filename,$data){
53 if(($filename = $this->
filename($filename)) && (($this->
total() + (is_file($filename) ? 0 : strlen($data))) <= $this->quota * 1048576)){
54 \Rsi\File::mkdir(dirname($filename));
55 return file_put_contents($filename,$data);
64 public function fetch($filename){
65 return ($filename = $this->
filename($filename)) ? \Rsi\File::read($filename,null) :
false;
72 public function delete($filename){
73 if(($filename = $this->
filename($filename)) && \Rsi\File::unlink($filename)){
74 $root = strlen($this->_root);
75 while((strlen($filename = dirname($filename)) > $root) && !(
new \FilesystemIterator($filename))->valid()) rmdir($filename);
84 foreach($this->
list() as $filename => $info) $this->
delete($filename);
save($filename, $data)
Save a file.
total()
Total size used (in bytes).
list($types=null)
List files.
$quota
Maximum total user files size (per user; in mega bytes).
filename($filename)
Get full filename for a file.
$_root
Root directory for the user files.
fetch($filename)
Read a file.