Exemple #1
0
function recurse($path, $callback)
{
    $path = _realpath($path);
    foreach (_scandir($path) as $file) {
        if ($file == '.' or $file == '..') {
            continue;
        }
        $realfile = _realpath("{$path}/{$file}");
        if (_is_dir($realfile)) {
            recurse($realfile, $callback);
        } else {
            $callback($realfile);
        }
    }
    $callback($path);
}
Exemple #2
0
 public function setPath($path)
 {
     // Update
     if ($path == '*') {
         $path = $this->_path;
     }
     $path = _realpath($path);
     if (_file_exists($path) and _is_dir($path)) {
         if (_is_readable($path)) {
             $this->_path = $path;
             $this->_tree = _scandir($this->_path);
             $this->_size = count($this->_tree);
             return $this->_path;
         } else {
             throw new Exception("Can't read dir: {$path}");
         }
     } else {
         throw new Exception("Not a dir: {$path}");
     }
 }
 /**
  * Clean-up the temporary parts files in case of error|abort
  */
 public function _cleanup_parts($filename = false)
 {
     $filename || ($filename = $this->_filename);
     // file_put_contents( '/tmp/clean_up', $this->_tmp_dir . PHP_EOL );
     // file_put_contents( '/tmp/clean_up', $filename . PHP_EOL, 8 );
     if (_is_dir($this->_tmp_dir) && !empty($filename)) {
         foreach ($this->_get_parts(false, false, $filename) as $chunk_filename) {
             if (!empty($chunk_filename) && 0 === strpos($chunk_filename, $this->_tmp_dir) && _is_file($chunk_filename)) {
                 @unlink($chunk_filename);
                 // file_put_contents( '/tmp/clean_up', 'XXX:' . $chunk_filename . PHP_EOL, 8 );
             }
         }
     }
 }
Exemple #4
0
<?php

$MODULE = array('getFiles' => function () {
    $path = post('path');
    $FOLDER = new Folder($path);
    return array('files' => $FOLDER->getFiles(function ($file) use($FOLDER) {
        return $file->path != $FOLDER->path;
    }, function ($file) {
        return $file->toArray();
    }), 'info' => $FOLDER->toFileArray());
}, 'newFile' => function () {
    $path = post('path');
    return array('error' => File::create($path));
}, 'newFolder' => function () {
    $path = post('path');
    return array('error' => Folder::create($path));
}, 'delete' => function () {
    $path = post('path');
    $err = _is_dir($path) ? Folder::delete($path) : File::delete($path);
    return array('error' => $err);
}, 'unlock' => function () {
    $path = post('path');
    return array('error' => File::unlock($path));
});
Exemple #5
0
 public function isFile()
 {
     return !_is_dir($this->_path) and _is_file($this->_path);
 }