Пример #1
0
 public function load($spiBinaryFileId)
 {
     try {
         $info = $this->filesystem->getMetadata($spiBinaryFileId);
     } catch (FileNotFoundException $e) {
         throw new BinaryFileNotFoundException($spiBinaryFileId);
     }
     $spiBinaryFile = new SPIBinaryFile();
     $spiBinaryFile->id = $spiBinaryFileId;
     $spiBinaryFile->mtime = new DateTime('@' . $info['timestamp']);
     $spiBinaryFile->size = $info['size'];
     return $spiBinaryFile;
 }
 /**
  * Uploads raw contents to the service.
  *
  * @param string $contents
  * @return array    The meta of the file.
  */
 public function uploadContents($name, $contents)
 {
     $this->filesystem->write($name, $contents);
     $meta = $this->filesystem->getMetadata($name);
     $urlGenerator = app('Flarum\\Forum\\UrlGenerator');
     if (empty($this->settings->get('flagrow.image-upload.cdnUrl'))) {
         // if there is no cdnUrl
         $meta['url'] = $urlGenerator->toPath('assets/images/' . $name);
     } else {
         // if there is
         $meta['url'] = $this->settings->get('flagrow.image-upload.cdnUrl') . 'assets/images/' . $name;
     }
     return $meta;
 }
 /**
  * Return stat for given path.
  * Stat contains following fields:
  * - (int)    size    file size in b. required
  * - (int)    ts      file modification time in unix time. required
  * - (string) mime    mimetype. required for folders, others - optionally
  * - (bool)   read    read permissions. required
  * - (bool)   write   write permissions. required
  * - (bool)   locked  is object locked. optionally
  * - (bool)   hidden  is object hidden. optionally
  * - (string) alias   for symlinks - link target path relative to root path. optionally
  * - (string) target  for symlinks - link target path. optionally
  *
  * If file does not exists - returns empty array or false.
  *
  * @param  string  $path    file path
  * @return array|false
  **/
 protected function _stat($path)
 {
     $stat = array('mime' => 'directory', 'ts' => time(), 'read' => true, 'write' => true, 'locked' => false, 'hidden' => false, 'size' => 0);
     // If root, just return from above
     if ($this->root == $path) {
         $stat['name'] = $this->root;
         return $stat;
     }
     // If not exists, return empty
     if (!$this->fs->has($path)) {
         return array();
     }
     $meta = $this->fs->getMetadata($path);
     // Get timestamp/size
     $stat['ts'] = isset($meta['timestamp']) ? $meta['timestamp'] : $this->fs->getTimestamp($path);
     $stat['size'] = isset($meta['size']) ? $meta['size'] : $this->fs->getSize($path);
     // Check if file, if so, check mimetype
     if ($meta['type'] == 'file') {
         $stat['mime'] = isset($meta['mimetype']) ? $meta['mimetype'] : $this->fs->getMimetype($path);
         $imgMimes = ['image/jpeg', 'image/png', 'image/gif'];
         if ($this->urlBuilder && in_array($stat['mime'], $imgMimes)) {
             $stat['url'] = $this->urlBuilder->getUrl($path, ['ts' => $stat['ts']]);
             $stat['tmb'] = $this->urlBuilder->getUrl($path, ['ts' => $stat['ts'], 'w' => $this->tmbSize, 'h' => $this->tmbSize, 'fit' => $this->options['tmbCrop'] ? 'crop' : 'contain']);
         }
     }
     if (!isset($stat['url']) && $this->fs->getUrl()) {
         $stat['url'] = 1;
     }
     return $stat;
 }
Пример #4
0
 /**
  * Return stat for given path.
  * Stat contains following fields:
  * - (int)    size    file size in b. required
  * - (int)    ts      file modification time in unix time. required
  * - (string) mime    mimetype. required for folders, others - optionally
  * - (bool)   read    read permissions. required
  * - (bool)   write   write permissions. required
  * - (bool)   locked  is object locked. optionally
  * - (bool)   hidden  is object hidden. optionally
  * - (string) alias   for symlinks - link target path relative to root path. optionally
  * - (string) target  for symlinks - link target path. optionally
  *
  * If file does not exists - returns empty array or false.
  *
  * @param  string $path file path
  * @return array|false
  **/
 protected function _stat($path)
 {
     $stat = array('size' => 0, 'ts' => time(), 'read' => true, 'write' => true, 'locked' => false, 'hidden' => false, 'mime' => 'directory');
     // If root, just return from above
     if ($this->root == $path) {
         $stat['name'] = $this->root;
         return $stat;
     }
     // If not exists, return empty
     if (!$this->fs->has($path)) {
         // Check if the parent doesn't have this path
         if ($this->_dirExists($path)) {
             return $stat;
         }
         // Neither a file or directory exist, return empty
         return array();
     }
     try {
         $meta = $this->fs->getMetadata($path);
     } catch (\Exception $e) {
         return array();
     }
     if (false === $meta) {
         return $stat;
     }
     // Set item filename.extension to `name` if exists
     if (isset($meta['filename']) && isset($meta['extension'])) {
         $stat['name'] = $meta['filename'];
         if ($meta['extension'] !== '') {
             $stat['name'] .= '.' . $meta['extension'];
         }
     }
     // Get timestamp/size if available
     if (isset($meta['timestamp'])) {
         $stat['ts'] = $meta['timestamp'];
     }
     if (isset($meta['size'])) {
         $stat['size'] = $meta['size'];
     }
     // Check if file, if so, check mimetype when available
     if ($meta['type'] == 'file') {
         if (isset($meta['mimetype'])) {
             $stat['mime'] = $meta['mimetype'];
         } else {
             $stat['mime'] = $this->fs->getMimetype($path);
         }
         $imgMimes = ['image/jpeg', 'image/png', 'image/gif'];
         if ($this->urlBuilder && in_array($stat['mime'], $imgMimes)) {
             $stat['url'] = $this->urlBuilder->getUrl($path, ['ts' => $stat['ts']]);
             $stat['tmb'] = $this->urlBuilder->getUrl($path, ['ts' => $stat['ts'], 'w' => $this->tmbSize, 'h' => $this->tmbSize, 'fit' => $this->options['tmbCrop'] ? 'crop' : 'contain']);
         }
     }
     if (!isset($stat['url']) && $this->fs->getUrl()) {
         $stat['url'] = 1;
     }
     return $stat;
 }
Пример #5
0
 /**
  * @override
  * @inheritDoc
  */
 public function getType($path)
 {
     try {
         return $this->fs->getMetadata($path)['type'];
     } catch (Error $ex) {
     } catch (Exception $ex) {
     }
     throw new ReadException("File {$path} type could not be determined.", $ex);
 }
Пример #6
0
 /**
  * Extracts a specific FileInformation from the FileSystems.
  *
  * @param string $fileIdentifier
  * @param string $containerPath
  * @param string $property
  *
  * @return bool|int|string
  * @throws \InvalidArgumentException
  */
 public function getSpecificFileInformation($fileIdentifier, $containerPath, $property)
 {
     $baseName = basename($fileIdentifier);
     $parts = explode('/', $fileIdentifier);
     $identifier = $this->canonicalizeAndCheckFileIdentifier($containerPath . PathUtility::basename($fileIdentifier));
     $file = $this->filesystem->getMetadata($fileIdentifier);
     switch ($property) {
         case 'size':
             return $file['size'];
         case 'atime':
             return $file['timestamp'];
         case 'mtime':
             return $file['timestamp'];
         case 'ctime':
             return $file['timestamp'];
         case 'name':
             return $baseName;
         case 'mimetype':
             return 'application/octet-stream';
         case 'identifier':
             return $identifier;
         case 'storage':
             return $this->storageUid;
         case 'identifier_hash':
             return $this->hashIdentifier($identifier);
         case 'folder_hash':
             if (1 < count($parts)) {
                 return $this->hashIdentifier($this->getParentFolderIdentifierOfIdentifier($identifier));
             } elseif (1 === count($parts)) {
                 return sha1('/');
             } else {
                 return '';
             }
         default:
             throw new \InvalidArgumentException(sprintf('The information "%s" is not available.', $property));
     }
 }
Пример #7
0
 /**
  * Retrieve the entree type (file|dir).
  *
  * @return string file or dir
  */
 public function getType()
 {
     $metadata = $this->filesystem->getMetadata($this->path);
     return $metadata['type'];
 }
Пример #8
0
 /**
  * Get a file's metadata.
  *
  * @param string $path The path to the file.
  *
  * @throws FileNotFoundException
  *
  * @return array|false The file metadata or false on failure.
  */
 public function getMetadata($path)
 {
     return $this->fileSystem->getMetadata($path);
 }