예제 #1
0
파일: FilesBag.php 프로젝트: vvval/spiral
 /**
  * Get URI (virtual filename) associated with UploadedFile resource.
  *
  * @param string $name
  * @return null|string
  */
 public function uri($name)
 {
     if (!empty($file = $this->get($name)) && !$file->getError()) {
         return StreamWrapper::getUri($file->getStream());
     }
     return null;
 }
예제 #2
0
 /**
  * {@inheritdoc}
  */
 public function put(BucketInterface $bucket, $name, $source)
 {
     if ($source instanceof StreamInterface) {
         $expectedSize = $source->getSize();
         $source = StreamWrapper::getResource($source);
     } else {
         $expectedSize = filesize($source);
         $source = fopen($source, 'r');
     }
     //Make sure target directory exists
     $this->ensureLocation($bucket, $name);
     //Remote file
     $destination = fopen($this->getUri($bucket, $name), 'w');
     //We can check size here
     $size = stream_copy_to_stream($source, $destination);
     fclose($source);
     fclose($destination);
     return $expectedSize == $size && $this->refreshPermissions($bucket, $name);
 }
예제 #3
0
 /**
  * Internal method to fetch filename using multiple input formats.
  *
  * @param mixed|UploadedFileInterface $filename
  * @param bool                        $onlyUploaded Check if file uploaded.
  * @return string|bool
  */
 protected function filename($filename, $onlyUploaded = true)
 {
     if (empty($filename) || $onlyUploaded && !$this->isUploaded($filename)) {
         return false;
     }
     if ($filename instanceof UploadedFileInterface || $filename instanceof StreamableInterface) {
         return StreamWrapper::getUri($filename->getStream());
     }
     if (is_array($filename)) {
         $filename = $filename['tmp_name'];
     }
     return $this->files->exists($filename) ? $filename : false;
 }
예제 #4
0
 /**
  * Cast local filename to be used in file based methods and etc.
  *
  * @param string|StreamInterface $source
  * @return string
  */
 protected function castFilename($source)
 {
     if (empty($source)) {
         return StreamWrapper::getUri(\GuzzleHttp\Psr7\stream_for(''));
     }
     if (is_string($source)) {
         if ($this->files->exists($source)) {
             return $source;
         } else {
             return StreamWrapper::getUri(\GuzzleHttp\Psr7\stream_for($source));
         }
     }
     if ($source instanceof UploadedFileInterface || $source instanceof StreamableInterface) {
         $source = $source->getStream();
     }
     if ($source instanceof StreamInterface) {
         return StreamWrapper::getUri($source);
     }
     throw new ServerException("Unable to get filename for non Stream instance.");
 }
예제 #5
0
 /**
  * Cast local filename to be used in file based methods and etc.
  *
  * @param string|StreamInterface $source
  * @return string
  */
 protected function castFilename($source)
 {
     if (empty($source) || is_string($source)) {
         if (!$this->files->exists($source)) {
             //This code is going to use additional abstraction layer to connect storage and guzzle
             return StreamWrapper::getUri(\GuzzleHttp\Psr7\stream_for(''));
         }
         return $source;
     }
     if ($source instanceof UploadedFileInterface || $source instanceof StreamableInterface) {
         $source = $source->getStream();
     }
     if ($source instanceof StreamInterface) {
         return StreamWrapper::getUri($source);
     }
     throw new ServerException("Unable to get filename for non Stream instance.");
 }