コード例 #1
0
 /**
  * Download $remote_path directory recursive as $local_path.
  * 
  * @throws
  * @param string $remote_path
  * @param string $local_path
  * @return vector<string>
  */
 public function getDir($remote_path, $local_path)
 {
     $entries = $this->ls($remote_path);
     Dir::create($local_path, 0, true);
     foreach ($entries as $path => $info) {
         if ($info['type'] === 'f') {
             $this->get($path, $local_path . '/' . $info['name']);
         } else {
             if ($info['type'] === 'l') {
                 if (FSEntry::isLink($local_path . '/' . $info['name'], false)) {
                     File::remove($local_path . '/' . $info['name']);
                 }
                 print "link: " . $info['link'] . " - " . $local_path . '/' . $info['name'] . "\n";
                 FSEntry::link($info['link'], $local_path . '/' . $info['name'], false);
             } else {
                 if ($info['type'] === 'd') {
                     $this->getDir($path, $local_path . '/' . $info['name']);
                 }
             }
         }
     }
 }
コード例 #2
0
 /**
  * Return directory size (= sum of all filesizes in directory tree).
  *
  * @param string $path
  * @return int
  */
 public static function size($path)
 {
     $entries = Dir::entries($path);
     $size = 0;
     foreach ($entries as $entry) {
         if (FSEntry::isDir($entry, false)) {
             $size += Dir::size($entry);
         } else {
             if (FSEntry::isFile($entry, false)) {
                 $size += File::size($entry);
             }
         }
     }
     return $size;
 }
コード例 #3
0
 /**
  * Send file as http download. Use disposition = 'inline' for in browser display.
  * Exit after send. If file does not exist send 404 not found.
  *
  * @param string $file
  * @param string|bool $disposition (default = attachment = true)
  * 
  */
 public static function httpSend($file, $disposition = 'attachment')
 {
     if (!FSEntry::isFile($file, false)) {
         header("HTTP/1.0 404 Not Found");
         exit;
     }
     $mime_type = File::mime($file);
     $content_type = empty($mime_type) ? 'application/force-download' : $mime_type;
     // send header
     header('HTTP/1.1 200 OK');
     // IE is the shit ... needs cache control headers ...
     header('Pragma: public');
     header('Expires: 0');
     header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
     header('Cache-Control: private', false);
     $fsize = filesize($file);
     header('Date: ' . date("D M j G:i:s T Y"));
     header('Last-Modified: ' . date("D M j G:i:s T Y"));
     header('Content-Type: ' . $content_type);
     header('Content-Length: ' . $fsize);
     header('Content-Transfer-Encoding: binary');
     if ($disposition === true) {
         // keep compatibility to old version
         $disposition = 'attachment';
     }
     if ($disposition === 'attachment' || $disposition === 'inline') {
         $fname = basename($file);
         header('Content-Description: File Transfer');
         header('Content-Disposition: ' . $disposition . '; filename="' . $fname . '"');
     }
     if ($fsize > 1048576 * 50) {
         // 50 MB+ ... flush the file ... otherwise the download dialog doesn't show up ...
         $fp = fopen($file, 'rb');
         while (!feof($fp)) {
             print fread($fp, 65536);
             flush();
         }
         fclose($fp);
     } else {
         // send file content
         readfile($file);
     }
     exit;
 }
コード例 #4
0
 /**
  * Run test script.
  *
  * @param string $run_php
  */
 public function runTest($run_php)
 {
     FSEntry::isFile($run_php);
     $script_dir = dirname($run_php);
     $this->_tc['num'] = 0;
     $this->_tc['ok'] = 0;
     $this->_tc['error'] = 0;
     $this->_tc['path'] = $script_dir;
     $this->_log('START: ' . $script_dir . ' Tests', 15);
     // execute tests ...
     include $run_php;
     $result = '';
     $this->_tc['t_num'] += $this->_tc['num'];
     if ($this->_tc['error'] == 0 && $this->_tc['ok'] > 0) {
         $this->_tc['t_ok'] += $this->_tc['ok'];
         $this->_tc['t_pass']++;
         $result = 'PASS';
     } else {
         $this->_tc['t_error'] += $this->_tc['error'];
         $this->_tc['t_fail']++;
         $result = 'FAIL';
     }
     $this->_log('RESULT: ' . $this->_tc['ok'] . '/' . $this->_tc['num'] . ' OK - ' . $this->_tc['error'] . " ERROR \t" . $result, 31);
     $overview = sprintf("%16s: %3d/%-3d ok - %3d errors", dirname($run_php), $this->_tc['ok'], $this->_tc['num'], $this->_tc['error']);
     array_push($this->_tc['overview'], $overview);
 }