Uploading multiple files. Error Invalid data type, must be an array or \ArrayAccess instance

Hello everyone i just started out using cakephp and php in general. First thank you Jose Gonzalez for the Plugin it really did help me a lot, while figuring out how to upload pictures.

Multiple file upload works for me when only choosing two pictures, once i extend that to 3 or 4 i get this error message: Invalid data type, must be an array or \ArrayAccess instance.

I already got the suggestion to change the:
post_max_size=20M
upload_max_filesize=20M
And even though the total upload size is 500kb i still get an error message.

Here is the part of the Table I am working on. Thanks in advance for your help.

public function initialize(array $config)
{
$this->setPrimaryKey(‘id’);
$this->belongsToMany(‘Tags’);
$this->addBehavior(‘Timestamp’);

    $this->addBehavior('Josegonzalez/Upload.Upload', [
        //works with two
        'photolg',
        //stops working with 3rd and 4th
        //'photomd',
        //'photosm',
        'photo' => [
            'fields' => [
                'dir' => 'photo_dir',
            ],
            'nameCallback' => function ($table, $entity, $data, $field, $settings) {
                return strtolower($data['name']);
            },
            'transformer' =>  function ($table, $entity, $data, $field, $settings) {
                $extension = pathinfo($data['name'], PATHINFO_EXTENSION);

                // Store the thumbnail in a temporary file
                $tmp = tempnam(sys_get_temp_dir(), 'upload') . '.' . $extension;

                // Use the Imagine library to DO THE THING
                $size = new \Imagine\Image\Box(100, 100);
                $mode = \Imagine\Image\ImageInterface::THUMBNAIL_INSET;
                $imagine = new \Imagine\Gd\Imagine();

                // Save that modified file to our temp file
                $imagine->open($data['tmp_name'])
                    ->thumbnail($size, $mode)
                    ->save($tmp);

                // Now return the original *and* the thumbnail
                return [
                    $data['tmp_name'] => $data['name'],
                    $tmp => 'thumbnail-' . $data['name'],
                ];
            },
            'deleteCallback' => function ($path, $entity, $field, $settings) {
                // When deleting the entity, both the original and the thumbnail will be removed
                // when keepFilesOnDelete is set to false
                return [
                    $path . $entity->{$field},
                    $path . 'thumbnail-' . $entity->{$field}
                ];
            },
            'keepFilesOnDelete' => false
        ]
    ]);
}

I got help over at GitHub, and the Problem is now solved. The working table looks like this now (NOT PRETTY and a lot of repeating if you got a better solution let me know please!):

public function initialize(array $config)
{
$this->setPrimaryKey(‘id’);
$this->belongsToMany(‘Tags’);
$this->addBehavior(‘Timestamp’);

$this->addBehavior(‘Josegonzalez/Upload.Upload’, [

‘photolg’=> [
‘fields’ => [
‘dir’ => ‘photolg_dir’,
],
‘nameCallback’ => function ($table, $entity, $data, $field, $settings) {
return strtolower($data[‘name’]);
},
‘transformer’ => function ($table, $entity, $data, $field, $settings) {
$extension = pathinfo($data[‘name’], PATHINFO_EXTENSION);

// Store the thumbnail in a temporary file
$tmp = tempnam(sys_get_temp_dir(), ‘upload’) . ‘.’ . $extension;

// Use the Imagine library to DO THE THING
$size = new \Imagine\Image\Box(100, 100);
$mode = \Imagine\Image\ImageInterface::THUMBNAIL_INSET;
$imagine = new \Imagine\Gd\Imagine();

// Save that modified file to our temp file
$imagine->open($data[‘tmp_name’])
->thumbnail($size, $mode)
->save($tmp);

// Now return the original and the thumbnail
return [
$data[‘tmp_name’] => $data[‘name’],
$tmp => ‘thumbnail-’ . $data[‘name’],
];
},
‘deleteCallback’ => function ($path, $entity, $field, $settings) {
// When deleting the entity, both the original and the thumbnail will be removed
// when keepFilesOnDelete is set to false
return [
$path . $entity->{$field},
$path . ‘thumbnail-’ . $entity->{$field}
];
},
‘keepFilesOnDelete’ => false
],

‘photomd’=> [
‘fields’ => [
‘dir’ => ‘photomd_dir’,
],
‘nameCallback’ => function ($table, $entity, $data, $field, $settings) {
return strtolower($data[‘name’]);
},
‘transformer’ => function ($table, $entity, $data, $field, $settings) {
$extension = pathinfo($data[‘name’], PATHINFO_EXTENSION);

// Store the thumbnail in a temporary file
$tmp = tempnam(sys_get_temp_dir(), ‘upload’) . ‘.’ . $extension;

// Use the Imagine library to DO THE THING
$size = new \Imagine\Image\Box(100, 100);
$mode = \Imagine\Image\ImageInterface::THUMBNAIL_INSET;
$imagine = new \Imagine\Gd\Imagine();

// Save that modified file to our temp file
$imagine->open($data[‘tmp_name’])
->thumbnail($size, $mode)
->save($tmp);

// Now return the original and the thumbnail
return [
$data[‘tmp_name’] => $data[‘name’],
$tmp => ‘thumbnail-’ . $data[‘name’],
];
},
‘deleteCallback’ => function ($path, $entity, $field, $settings) {
// When deleting the entity, both the original and the thumbnail will be removed
// when keepFilesOnDelete is set to false
return [
$path . $entity->{$field},
$path . ‘thumbnail-’ . $entity->{$field}
];
},
‘keepFilesOnDelete’ => false
],

‘photosm’=> [
‘fields’ => [
‘dir’ => ‘photosm_dir’,
],
‘nameCallback’ => function ($table, $entity, $data, $field, $settings) {
return strtolower($data[‘name’]);
},
‘transformer’ => function ($table, $entity, $data, $field, $settings) {
$extension = pathinfo($data[‘name’], PATHINFO_EXTENSION);

// Store the thumbnail in a temporary file
$tmp = tempnam(sys_get_temp_dir(), ‘upload’) . ‘.’ . $extension;

// Use the Imagine library to DO THE THING
$size = new \Imagine\Image\Box(100, 100);
$mode = \Imagine\Image\ImageInterface::THUMBNAIL_INSET;
$imagine = new \Imagine\Gd\Imagine();

// Save that modified file to our temp file
$imagine->open($data[‘tmp_name’])
->thumbnail($size, $mode)
->save($tmp);

// Now return the original and the thumbnail
return [
$data[‘tmp_name’] => $data[‘name’],
$tmp => ‘thumbnail-’ . $data[‘name’],
];
},
‘deleteCallback’ => function ($path, $entity, $field, $settings) {
// When deleting the entity, both the original and the thumbnail will be removed
// when keepFilesOnDelete is set to false
return [
$path . $entity->{$field},
$path . ‘thumbnail-’ . $entity->{$field}
];
},
‘keepFilesOnDelete’ => false
],

‘photo’ => [
‘fields’ => [
‘dir’ => ‘photo_dir’,
],
‘nameCallback’ => function ($table, $entity, $data, $field, $settings) {
return strtolower($data[‘name’]);
},
‘transformer’ => function ($table, $entity, $data, $field, $settings) {
$extension = pathinfo($data[‘name’], PATHINFO_EXTENSION);

// Store the thumbnail in a temporary file
$tmp = tempnam(sys_get_temp_dir(), ‘upload’) . ‘.’ . $extension;

// Use the Imagine library to DO THE THING
$size = new \Imagine\Image\Box(100, 100);
$mode = \Imagine\Image\ImageInterface::THUMBNAIL_INSET;
$imagine = new \Imagine\Gd\Imagine();

// Save that modified file to our temp file
$imagine->open($data[‘tmp_name’])
->thumbnail($size, $mode)
->save($tmp);

// Now return the original and the thumbnail
return [
$data[‘tmp_name’] => $data[‘name’],
$tmp => ‘thumbnail-’ . $data[‘name’],
];
},
‘deleteCallback’ => function ($path, $entity, $field, $settings) {
// When deleting the entity, both the original and the thumbnail will be removed
// when keepFilesOnDelete is set to false
return [
$path . $entity->{$field},
$path . ‘thumbnail-’ . $entity->{$field}
];
},
‘keepFilesOnDelete’ => false
]
]);
}