Beispiel #1
0
 private static function _zipDir(Folder $dir, \ZipArchive $zip, $relative_path)
 {
     $items = $dir->ls();
     if (count($items)) {
         foreach ($items as $item) {
             if ($item->isFile()) {
                 $name = $relative_path . $item->name();
                 $name = @iconv('UTF-8', 'CP850//TRANSLIT', $name);
                 \GO::debug("Add file: " . $name);
                 $zip->addFile($dir->path() . '/' . $item->name(), $name);
             } else {
                 self::_zipDir($item, $zip, $relative_path . $item->name() . '/');
             }
         }
     } else {
         \GO::debug("Add empty dir: " . $relative_path);
         if (!$zip->addEmptyDir(rtrim($relative_path, '/'))) {
             throw new \Exception("Could not add emty directory " . $relative_path);
         }
     }
 }
Beispiel #2
0
 /**
  *
  * @param array $uploadedFileArray
  * @param Folder  $destinationFolder
  * @param boolean $overwrite If false this function will append a number. eg. Filename (1).jpg
  * @return File[]
  */
 public static function moveUploadedFiles($uploadedFileArray, $destinationFolder, $overwrite = false)
 {
     if (!is_array($uploadedFileArray['tmp_name'])) {
         $uploadedFileArray['tmp_name'] = array($uploadedFileArray['tmp_name']);
         $uploadedFileArray['name'] = array($uploadedFileArray['name']);
     }
     $files = array();
     for ($i = 0; $i < count($uploadedFileArray['tmp_name']); $i++) {
         if (is_uploaded_file($uploadedFileArray['tmp_name'][$i])) {
             $destinationFile = new File($destinationFolder->path() . '/' . $uploadedFileArray['name'][$i]);
             if (!$overwrite) {
                 $destinationFile->appendNumberToNameIfExists();
             }
             if (move_uploaded_file($uploadedFileArray['tmp_name'][$i], $destinationFile->path())) {
                 $destinationFile->setDefaultPermissions();
                 $files[] = $destinationFile;
             }
         }
     }
     return $files;
 }
Beispiel #3
0
 public function rss()
 {
     setlocale(LC_ALL, 'en_US');
     $limit = 10;
     $ret = array();
     foreach ($this->folder->subFolders as $s) {
         $path = Folder::path($s);
         $uri = $path . '/last/' . $limit;
         $ret += Ctrl::fetchData($uri);
     }
     krsort($ret);
     return array_splice($ret, 0, $limit);
 }
Beispiel #4
0
 /**
  * Create a symbolic link in this folder
  * 
  * @param Folder $target
  * @param string $linkName optional link name. If omitted the name will be the same as the target folder name
  * @return File
  * @throws Exception
  */
 public function createLink(Folder $target, $linkName = null)
 {
     if (!isset($linkName)) {
         $linkName = $target->name();
     }
     $link = $this->createChild($linkName, true);
     if ($link->exists()) {
         throw new \Exception("Path " . $link->path() . " already exists");
     }
     if (symlink($target->path(), $link->path())) {
         return $link;
     } else {
         throw new \Exception("Failed to create link " . $link->path() . " to " . $target->path());
     }
 }