Okay Charles , that makes sense so I changed my code:
<?php
class Outlet extends CoasterCmsAppModel
{
public $validate = array(
'name' => array(
'rule' => 'notEmpty', // verplicht
'message' => 'Nameis required.',
'allowEmpty' => true
),
'intro' => array(
'rule' => 'notEmpty', // verplicht
'message' => 'Intro is required.'
),
'photo' => array(
'validFileSize' => array( // zelf gekozen naam van de regel
'rule' => array('filesize', '>', 0), // verplicht
'on' => 'create',
'message' => 'Photo is required.'
)
),
'photoTemp' => array(
'validExtension' => array( // zelf gekozen naam van de regel
'rule' => array('extension', array('jpg', 'jpeg', 'png',
'gif')),
'on' => 'create',
'message' => 'Photo has to contain a valid extension (jpg,
jpeg, png or gif).'
),
'validExtension' => array( // zelf gekozen naam van de regel
'rule' => array('extension', array('jpg', 'jpeg', 'png',
'gif')),
'allowEmpty' => true,
'on' => 'update',
'message' => 'Photo has to contain a valid extension (jpg,
jpeg, png or gif).'
)
)
);
public function beforeValidate()
{
$this->data['Outlet']['photoTemp'] = $this->data['Outlet']['photo'];
$this->data['Outlet']['photo'] = $this->data['Outlet']['photoTemp'][
'name'];
}
public function afterValidate()
{
$filename = $this->data['Outlet']['photo'];
if (!empty($filename)) {
move_uploaded_file($this->data['Outlet']['photoTemp']['tmp_name'
], WWW_ROOT . 'img' . DS . 'outlets' . DS . $filename);
} else {
unset($this->data['Outlet']['photo']);
}
unset($this->data['Outlet']['photoTemp']);
}
}
However, I still get the error message that I should upload a file with a
correct extension. It's just like 'allowEmpty' => true" isn't working at
all.
I quess in my case it's checking the value in $this->data['Outlet'][
'photoTemp']['type'] so what could possibly be the problem?
--
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.