PHP code example of t3n / graphql-upload
1. Go to this page and download the library: Download t3n/graphql-upload library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
t3n / graphql-upload example snippets
class MutationResolver implements ResolverInterface
{
/**
* @Flow\Inject
*
* @var ResourceManager
*/
protected $resourceManager;
public function uploadFile($_, $variables): string
{
/** @var FlowUploadedFile $file */
$file = $variables['file'];
$resource = $this->resourceManager->importResource($file->getStream()->detach());
$resource->setFilename($file->getClientFilename());
$resource->setMediaType($file->getClientMediaType());
return $file->getClientFilename();
}
}