yii - File type is not validated -
i'm trying validate file type before saving database. rule
array('picture', 'file', 'types'=>'jpg, gif, png, jpeg', 'allowempty'=>true, 'maxsize'=>1024*1024/*1mb*/, 'toolarge'=>yii::t('default', 'file large'), 'on'=>'create'), i'm trying upload multiple images
foreach($_files["picture"]["name"] $key=>$value) { $images->picture='file'; $images->idbuyitnow=1; if($images->validate()) echo $value." "; else echo "doesnt work"; } html code
<?php echo chtml::filefield('picture[]','',array('class'=>'form-control' ,'multiple'=>true, 'accept'=>'image/*')); ?> i know should utilize cmultiupload wanted create that. validate if $images->picture="file" or "25.docx". var_dump($images->validate()) returns true
[solved] weirdest thing ever, attribute shouldn't called "picture" "image" instead.
full solution
html
<?php echo chtml::filefield('image_file[]','',array('class'=>'form-control' ,'multiple'=>true, 'accept'=>'image/*')); ?> controller
$images=new buyitnowimage; $file=cuploadedfile::getinstancesbyname('image_file'); foreach($fileas $key=>$value) { $images->image_file=$value; $images->idbuyitnow=1; if($images->validate()) echo "ok"; else echo "not ok"; } model
array('image_file', 'file', 'types'=>'jpg, gif, png, jpeg', 'allowempty'=>true, 'maxsize'=>1024*1024/*1mb*/, 'toolarge'=>yii::t('default', 'file large')), yii
No comments:
Post a Comment