/** * 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; }
/** * {@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); }
/** * 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; }
/** * 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."); }
/** * 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."); }