Example #1
0
 static function ls($path)
 {
     $ipath = implode("/", $path);
     $r = new ResultSet();
     $dImages = new Dir(self::ROOT);
     $dir = $dImages->getDir($ipath);
     $dirs = $dir->ls(null, DIR::LS_DIR);
     $r->f("#dirs")->count(count($dirs))->f("#parent > whyperlink")->href(array_merge(array_slice($path, 0, -1), array(null)));
     foreach ($dirs as $k => $d) {
         $l = substr($d, strlen($dImages));
         $r->f("#cd > whyperlink", $k)->href(explode('/', $l))->f("#ddel", $k)->additional_id($d->getName())->f("#cd wtext", $k)->text($d->getName());
     }
     $fc = 0;
     foreach ($dir->ls() as $k => $f) {
         $df = new MimeDecorator(new StatDecorator($f));
         //if(strpos($df->getMime(),"image") === false) continue;
         try {
             $df = new ImageDecorator($df);
         } catch (DecoratorException $e) {
             continue;
         }
         $stat = $df->stat();
         @$r->f("#fname", $k)->text($df->getName())->f("#fdel", $k)->additional_id($df->getName())->f("#stat", $k)->text($df->getWidth() . "×" . $df->getHeight() . " " . date("Y/m/d H:i", $stat['mtime']) . " " . sizeToString($stat['size']))->f("#preview", $k)->file($df)->f("#choose > whyperlink", $k)->href($df->getURL());
         $fc++;
     }
     $r->f("#files")->count($fc);
     return $r;
 }
Example #2
0
 /**
  * Pass only files with filesize between max and min values.
  * Caution, action performs at the calling time.
  *
  * @param int max file size
  * @param int min file size
  * @return UploadedFiles object
  * @see allowedImageSize
  */
 function allowedSize($max = null, $min = 0)
 {
     if ($min === null || $max === null) {
         return $this;
     }
     $min = sizeFromString($min);
     $max = sizeFromString($max);
     foreach ($this->http_files as $k => $v) {
         $size = sprintf("%u", @filesize($v['tmp_name']));
         if ($min && $size < $min) {
             $this->http_error_files[$k][] = array('min_size', $v['name'], sizeToString($min), $size);
         } elseif ($max && $size > $max) {
             $this->http_error_files[$k][] = array('max_size', $v['name'], sizeToString($max), $size);
         }
     }
     return $this;
 }
Example #3
0
 /**
  * Treats given string as a numeric value, that represents 
  * file size in bytes. Returns pretty string, showing 
  * file size in KB, MB etc. 
  * If $flag is in not-false state, single whitespace between 
  * numbers and units will be placed. For example:
  * <pre><code>
  * 1048576 => 1MB
  * </code></pre>
  * @param numeric file size
  * @param bool to place or not whitespace before unit
  * @return string processed string
  */
 protected function filesize($size, $flag = 0)
 {
     return sizeToString($size, $flag);
 }
Example #4
0
 /**
  * Загружает пакет указанный в cgbcrt $url в $targetFile.
  * 
  * Проверяет хеш пакета. Останавливается после первого скачанного файла.
  *
  * @trows RepositoryListException 
  * @param array $urls list of URLS where package couldbe found
  * @param File $targetFile local file where fetched package has ben stored/
  * @return File $targetFile if fetching successfully.
  *
  *
  */
 function fetchPackage($urls, $targetFile)
 {
     foreach ($urls as $url) {
         try {
             $targetFile = $this->download($url, $targetFile);
             $remoteMd5 = $this->getRemoteMd5($url, true);
             if ($remoteMd5 == md5_file($targetFile)) {
                 io::out(' ' . $url . ' ( ' . sizeToString(filesize($targetFile)) . ' )', false);
                 return $targetFile;
             } else {
                 io::out('Downloaded file ' . $targetFile . ' not correspond to its md5 sum(' . $remoteMd5 . ')');
             }
         } catch (RepositoryListException $e) {
             if ($e->getCode() != 100) {
                 throw $e;
             }
         }
     }
     throw new RepositoryListException('Package ' . basename($url[0] . ' not found. Given urls: ' . implode(PHP_EOL . ', ', $urls)));
 }