Yii错误检测mimType

时间:2015-07-16 13:27:41

标签: php yii upload mime-types

我在yii 1.1中有一个应用程序,在CActiveRecord模型中有一个用于检查上传文件的mimType的规则

'mimeTypes'=>'jpg,jpeg,gif,png'

但是当我上传一个jpg文件时,它会给我一个错误:

the file "picture003.jpg" cannot be uploaded. Only files of these MIME-types are allowed: jpg, jpeg, gif, png.

我也试过这个:

'mimeTypes'=>'image/jpg,image/jpeg,image/gif,image/png'

有一段时间我收到此错误:

finfo_file(C:\xampp\tmp\phpD670.tmp): failed to open stream: No such file or directory 

1 个答案:

答案 0 :(得分:0)

这是正确的'mimeTypes'=>'image/jpg,image/jpeg,image/gif,image/png',以防止出现下一个错误

finfo_file(C:\xampp\tmp\phpD670.tmp): failed to open stream: No such file or directory

模型保存后使用文件保存,保存后将从temporrary目录中删除cuase文件。

if ( $model->save() ) {
   $model->image->saveAs(/*path*/);
}