I get this error:
Warning (2): Invalid argument supplied for foreach () [CORE \ Cake \ Utility \ Validation.php, line 490]
using the admin_upload_image action from my Galleries controller. But this action was working properly, and I did not modify it, except to place parameters for the upload validation.
Controller
public function admin_upload_image(){
/*if(!$this->Session->check('Admin')) {
$this->Session->setFlash('Está a aceder a uma zona restrita. Por favor faça Login.');
$this->redirect(array(
'controller' => 'admins',
'action' => 'login'));
}*/
$this->layout = 'admin_index';
if($this->request->is('post') || $this->request->is('put')) {
/* $file = $this->request->data['gallery_images']['path']['name'];*/
$file = array(
'GalleryImage' => array(
'path' => $this->request->data['gallery_images']['path']['name']
)
);
move_uploaded_file($this->data['gallery_images']['path']['tmp_name'], $_SERVER['DOCUMENT_ROOT'] . '/html/PushUp_app/app/webroot/img/gallery/' . $this->data['gallery_images']['path']['name']);
$this->loadModel('GalleryImage');
$this->GalleryImage->create();
if($this->GalleryImage->save($file)){
$this->Session->setFlash(__('Ficheiro carregado com sucesso!'));
}
else{
$this->Session->setFlash(__('Erro ao carregar o ficheiro!'));
}
}
}
View
<h2>Adicionar Fotografia</h2>
<?php
echo "<br>";
echo $this->Form->create('GalleryImage',array('type'=>'file'));
echo $this->Form->file('gallery_images.path');
echo "<br>";
//echo $this->Form->submit();
echo $this->Form->end('Guardar');
?>
Model
<?php
App::uses('AppModel', 'Model');
class GalleryImage extends AppModel{
//public $displayField ='path';
public $useTable = 'gallery_images';
//public $actsAs = array('MultipleDisplayFields' => array('fields' => array('path', 'id')));
var $name= 'GalleryImage';
var $validate= array(
'path' => array(
'rule' => array(
'allowEmpty' => true,
'extension', array('gif', 'jpeg', 'png', 'jpg', 'tiff'),
'fileSize', '<=', '40MB'
),
'message' => 'ERRO, a fotografia deve ter um tamanho inferior a 40MB.'
)
);
}
?>