I'm trying to do this With last 2.x CakePHP version, I'm trying to do a
upload multiple file form with validations but not working...
*DocsController.php (action add)*
if ($this->request->is('post')) {
if ($this->Doc->saveMany($this->request->data, array('deep' => true))) {
$this->Session->setFlash(__('Ok'));
} else {
debug($this->Doc->validationErrors); die();
$this->Session->setFlash(__('Error'));
}
$this->redirect($this->referer());}
*add.ctp*
<?php
echo $this->Form->create('Doc', array('type' => 'file'));
echo $this->Form->input('files.', array(
'label' => __("New document",true), 'type' => 'file',
'div' => 'input text no',
'multiple' => 'multiple',
'required' => true,));
echo $this->Form->end('Upload');?>
*Doc.php*
class Doc extends AppModel {
public $belongsTo = array(
'Project' => array(
'className' => 'Project',
'foreignKey' => 'project_id',
)
);
public $validate = array(
'files' => array(
'rule' => array('extension', array('pdf')),
'required' => false,
'allowEmpty' => true,
'message' => 'Only pdf files'
),
);}
*Arrays*
*This error is OK:*
Array(
[Doc] => Array
(
[files] => Array
(
[0] => Array
(
[name] => images.jpeg
[type] => image/jpeg
[tmp_name] => /private/var/tmp/phpSqerRI
[error] => 0
[size] => 5740
)
)
)
)
/app/Controller/DocsController.php (line 112)
array(
'Doc' => array(
'files' => array(
(int) 0 => 'Only pdf files'
)
))
*This is the problem:*
Array(
[Doc] => Array
(
[files] => Array
(
[0] => Array
(
[name] => 4_54718093804437603.pdf
[type] => application/pdf
[tmp_name] => /private/var/tmp/phpCfUUDx
[error] => 0
[size] => 1441232
)
)
)
)
/app/Controller/DocsController.php (line 112)
array(
'Doc' => array())
It's PDF, so OK but validation returns array
Why return array if no broke rules??
Thanks in advance, sorry for my english.
--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
---
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.