I have a file upload on an add view:
echo $this->Form->input('filename', array('type' => 'file'));
... and I use the following validation in the model:
var $validate = array(
'filename' => array(
'notempty' => array(
'rule' => array('notempty'),
'message' => 'Filename field must not be blank.'
),
'filetype' => array(
'rule' => array('check_file_type'),
'message' => 'File must be jpeg, jpg, png or
gif.'
)
)
);
function check_file_type($check) {
$field = key($check);
$value = $check[$field];
$ext = explode(".", $value);
$ext = $ext[count($ext) - 1];
if ($ext == "jpg" || $ext == "jpeg")
return true;
elseif ($ext == "png")
return true;
elseif ($ext == "gif")
return true;
return false;
}
However this is not working and it does not stop a bmp file I tried to
upload. What is wrong with my code?
Thanks.
--
Our newest site for the community: CakePHP Video Tutorials
http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others
with their CakePHP related questions.
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php