File upload not wroking

$name = $attachment->getClientFilename();
$type = $attachment->getClientMediaType();
$size = $attachment->getSize();
$tmpName = $attachment->getStream()->getMetadata(‘uri’);
$error = $attachment->getError();

getClientFilename() function is undefined. cakephp4.3

  1. Make sure your submitting form is of type file See Form - 4.x
echo $this->Form->create($entity, ['type' => 'file']);
// or if you don't have an entity form
echo $this->Form->create(null, ['type' => 'file']);
  1. Check the type of your submitted field in your controller.
$file = $this->getRequest()->getData('myfile');

if your file upload field is

echo $this->Form->control('myfile', ['type' => 'file']);

The file type of $file should be \Laminas\Diactoros\UploadedFile

  1. if its still not working (and you get an array instead of an object) please check that your App.uploadedFilesAsObjects config value is NOT set to false
1 Like