Yii 未验证文件类型
我正在尝试在将文件类型保存到数据库之前验证它。这是我的规矩Yii 未验证文件类型,yii,Yii,我正在尝试在将文件类型保存到数据库之前验证它。这是我的规矩 array('picture', 'file', 'types'=>'jpg, gif, png, jpeg', 'allowEmpty'=>true, 'maxSize'=>1024*1024/*1mb*/, 'tooLarge'=>Yii::t('default', 'File is too large'), 'on'=>'create'), 我正在尝试上载多个图像 foreach($_FILES["
array('picture', 'file', 'types'=>'jpg, gif, png, jpeg', 'allowEmpty'=>true, 'maxSize'=>1024*1024/*1mb*/, 'tooLarge'=>Yii::t('default', 'File is too large'), 'on'=>'create'),
我正在尝试上载多个图像
foreach($_FILES["picture"]["name"] as $key=>$value)
{
$images->picture='file';
$images->IDbuyitnow=1;
if($images->validate())
echo $value." ";
else
echo "doesnt work";
}
HTML代码
<?php echo CHtml::fileField('picture[]','',array('class'=>'form-control' ,'multiple'=>true, 'accept'=>'image/*')); ?>
我知道我应该使用CMultiUpload,但我想这样做。但即使$images->picture=file或25.docx,它也总是验证它。var_dump$images->validate返回true[SOLVED]有史以来最奇怪的事情,属性不应该称为picture,而应该称为image 全解 HTML 模型
<?php echo CHtml::fileField('image_file[]','',array('class'=>'form-control' ,'multiple'=>true, 'accept'=>'image/*')); ?>
$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";
}
array('image_file', 'file', 'types'=>'jpg, gif, png, jpeg', 'allowEmpty'=>true, 'maxSize'=>1024*1024/*1mb*/, 'tooLarge'=>Yii::t('default', 'File is too large')),