CakePHP-Proffer
CakePHP-Proffer copied to clipboard
Image file size error while uploading multiple images
CakePHP : 3.3
What I did ?
MyImagesTable.php
$this->addBehavior('Proffer.Proffer', [
'image' => [
'root' => WWW_ROOT . 'files',
'dir' => 'dir',
'thumbnailSizes' => [
'slide' => [
'w' => 600,
'h' => 795,
'fit' => true,
'jpeg_quality' => 90
],
],
'thumbnailMethod' => 'gd',
]
]);
$validator->provider('proffer', 'Proffer\Model\Validation\ProfferRules');
$validator
->add('image', 'proffer', [
'rule' => [
'dimensions', [
'min' => ['w' => 100, 'h' => 100],
'max' => ['w' => 2000, 'h' => 2000]
]
],
'message' => 'Image must be 100x100 to 2000x2000',
'provider' => 'proffer'
])
->allowEmpty('image');
add.ctp
<?= $this->Form->create($startupImage, ['type' => 'file']) ?>
<?= $this->Form->input('image[]', ['type' => 'file', 'multiple' => true, 'class' => '', 'label' => false]) ?>
<?= $this->Form->submit('Submit', ['class' => 'btn btn-success']) ?>
<?= $this->Form->end() ?>
Debug On debugging, it gives error as
Notice (8): Undefined index: tmp_name [ROOT/vendor/davidyell/proffer/src/Model/Validation/ProfferRules.php, line 29]
Warning (2): getimagesize() [<a href='http://php.net/function.getimagesize'>function.getimagesize</a>]: Filename cannot be empty [ROOT/vendor/davidyell/proffer/src/Model/Validation/ProfferRules.php, line 29]
'[errors]' => [
'image' => [
'proffer' => 'Image must be 100x100 to 2000x2000'
]
],
'[invalid]' => [
'image' => [
(int) 0 => [
'name' => 'my image.png',
'type' => 'image/png',
'tmp_name' => '/tmp/php19XFnW',
'error' => (int) 0,
'size' => (int) 113696
]
]
],
What I tried more ?
removed [] array and multiple => true from input field and tried uploading single file and it works.
Ah yes, I would imagine that the validation updates slipped through the development of the multi-upload featrure. This means I should have a test case here as well.
Thanks for reporting this, I'll take a look when I get a chance.