Hi, if I am trying to upload many pictures at the same time i am getting an error that says: ‘Object of class Laminas\Diactoros\UploadedFile could not be converted to string’
StartsController.php:
if ($this->request->is('post')) {
$start->steps[] = $start;
$start->setDirty('steps', true);
$image2 = $this->request->getData();
debug($image2);
$recipe = $this->Start->patchEntity($start, $this->request->getData(), ['associated' =>
['Steps']]);
add.php (view):
echo $this->Form->control(‘steps.0.image’,[‘type’=>‘file’]);
StepsTable.php:
$validator
->allowEmptyFile('image')
->add( 'image', [
'mimeType' => [
'rule' => [ 'mimeType', [ 'image/jpg', 'image/png', 'image/jpeg' ] ],
'message' => 'Please upload only jpg and png.',
],
'fileSize' => [
'rule' => [ 'fileSize', '<=', '1MB' ],
'message' => 'Image file size must be less than 1MB.',
],
] );
The debug($image2) throws:
APP/Controller/StartsController.php (line 642)
[
‘title’ => ‘test’,
‘steps’ => [
(int) 0 => [
‘body’ => ‘test’,
‘image’ => object(Laminas\Diactoros\UploadedFile) id:0 {
private clientFilename => ‘test.jpg’
private clientMediaType => ‘image/jpeg’
private error => (int) 0
private file => ‘/tmp/phpsxf4LO’
private moved => false
private size => (int) 61717
private stream => null
},
],
but the $recipe = $this->Start->patchEntity($start, $this->request->getData(), [‘associated’ => [‘Steps’]]); throws the error:
Object of class Laminas\Diactoros\UploadedFile could not be converted to string📋
Any ideas? Thanks…