Hi,
I’m trying to upload a file using postman (following the docs) and I’m getting an error at this line:
$directory = $this->get('upload_directory');
I expect this relates to the container, in my settings file I have this:
//Upload directory
$settings['upload_directory'] = $settings['root'] . '/uploads';
How can I get the upload_directory
into my __invoke
method?
Also is UPLOAD_ERR_OK
defined anywhere, doesn’t look like it. How/where should this be defined?
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, array $args): ResponseInterface
{
$supplier = (string)$args['supplier'];
$responseData = ['supplier' => $supplier];
$directory = $this->get('upload_directory');
$uploadedFiles = $request->getUploadedFiles();
// handle single input with single file upload
$uploadedFile = $uploadedFiles['supplier'];
if ($uploadedFile->getError() === UPLOAD_ERR_OK) {
$filename = $this->moveUploadedFile($directory, $uploadedFile);
$responseData = [
'filename' => $filename,
'supplier' => $supplier,
'message' => 'File uploaded'
];
//$response->getBody()->write('Uploaded: ' . $filename . '<br/>');
}
// Invoke the Responder and pass in the response and responseData ($responseData)
return $this->responder->withJson($response, $responseData);
}