I've been toying with a barebones application using this behavior, and I discovered this problem in the following scenario:
My file upload validator was set to not allow file uploads over 1MB. Sometimes it would work and I would get a "file too large" error on the entity, but sometimes the post would succeed and the file would simply not be uploaded.
I was a bit baffled by this, and it took me entirely too long to figure out that the silent failure was due to some files exceeding the upload_max_filesize parameter in php.ini. No error is thrown, and nothing is printed in the logs referencing it. It would be very nice to have some kind of notification, particularly an error returned on the entity when this occurs.
I traced the error to here in cakephp-upload/src/Model/Behavior/UploadBehavior.php:
public function beforeMarshal(Event $event, ArrayObject $data, ArrayObject $options)
{
$validator = $this->_table->validator();
$dataArray = $data->getArrayCopy();
foreach (array_keys($this->config()) as $field) {
if (!$validator->isEmptyAllowed($field, false)) {
continue;
}
if (Hash::get($dataArray, $field . '.error') !== UPLOAD_ERR_NO_FILE) {
continue;
}
unset($data[$field]);
}
}
Where the hash of the error in this scenario will correspond to UPLOAD_ERR_INI_SIZE in CakePHP's Core.php file. I'm not sure if this is the right place to handle the error, but this is where I discovered it.
I've been toying with a barebones application using this behavior, and I discovered this problem in the following scenario:
My file upload validator was set to not allow file uploads over 1MB. Sometimes it would work and I would get a "file too large" error on the entity, but sometimes the post would succeed and the file would simply not be uploaded.
I was a bit baffled by this, and it took me entirely too long to figure out that the silent failure was due to some files exceeding the
upload_max_filesize
parameter inphp.ini
. No error is thrown, and nothing is printed in the logs referencing it. It would be very nice to have some kind of notification, particularly an error returned on the entity when this occurs.I traced the error to here in
cakephp-upload/src/Model/Behavior/UploadBehavior.php
:Where the hash of the error in this scenario will correspond to
UPLOAD_ERR_INI_SIZE
in CakePHP'sCore.php
file. I'm not sure if this is the right place to handle the error, but this is where I discovered it.