Neos\Flow\ResourceManagement\Storage\WritableFileSystemStorage::importResource PHP Method

importResource() public method

On a successful import this method returns a PersistentResource object representing the newly imported persistent resource.
public importResource ( string | resource $source, string $collectionName ) : PersistentResource
$source string | resource
$collectionName string Name of the collection the new PersistentResource belongs to
return Neos\Flow\ResourceManagement\PersistentResource A resource object representing the imported resource
    public function importResource($source, $collectionName)
    {
        $temporaryTargetPathAndFilename = $this->environment->getPathToTemporaryDirectory() . uniqid('TYPO3_Flow_ResourceImport_');
        if (is_resource($source)) {
            try {
                $target = fopen($temporaryTargetPathAndFilename, 'wb');
                stream_copy_to_stream($source, $target);
                fclose($target);
            } catch (\Exception $exception) {
                throw new StorageException(sprintf('Could import the content stream to temporary file "%s".', $temporaryTargetPathAndFilename), 1380880079);
            }
        } else {
            try {
                copy($source, $temporaryTargetPathAndFilename);
            } catch (\Exception $exception) {
                throw new StorageException(sprintf('Could not copy the file from "%s" to temporary file "%s".', $source, $temporaryTargetPathAndFilename), 1375198876);
            }
        }
        return $this->importTemporaryFile($temporaryTargetPathAndFilename, $collectionName);
    }