For starters I see two possibly unrelated issues:
a) you should use "last"=>true in every rule
b) $value = array_shift($check) does the trick, as well

but did you actually try to debug your code before asking here?
I doubt that $value contains a string either way.
Usually uploads are "arrays" after a POST.
So it would be $value['filename'] etc


On 17 Dez., 19:01, Daniel <[email protected]> wrote:
> 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

Reply via email to