【问题标题】:yii unsecure attribute while using mimetypes file validation使用 mimetypes 文件验证时的 yii 不安全属性
【发布时间】:2012-09-27 15:17:56
【问题描述】:

我使用以下 mime 类型文件验证

 array('image', 'file', 'allowEmpty' => true,'mimeTypes'=>'image/gif, image/jpeg, image/jpg, image/png', 'on' => 'update')

如果文件没有正确的 mime 类型,则效果很好。 但如果验证成功,则日志 sais

2012/09/27 17:13:02 [warning] [application] unsafe Attribut "image" couldnt be set.

但它肯定被声明为保存

array('image', 'safe', 'on' => 'update')

这就是为什么我收到这样的错误

finfo_file(C:\xampp\tmp\php3729.tmp): failed to open stream: No such file or directory
$mimeType=finfo_file($info,$file->getTempName());

似乎,文件不能保存在它的不安全属性中。 奇怪的是,如果我使用 mimeTypes 检查取消注释验证规则,一切正常。

在我的控制器中,我像这样设置图像文件

   if (isset($_POST['User'])) {
            $user->attributes = $_POST['User'];
            $user->image = CUploadedFile::getInstance($user, 'image');
            if ($user->validate()) {

【问题讨论】:

    标签: validation file-upload yii mime-types runtime-error


    【解决方案1】:

    我相信您在保存整个模型之前运行$user->image->saveAs($path),这就是为什么当它已经移动到 $path 时它会尝试验证临时文件夹中的文件。 所以,保存模型后使用$user->validate()或运行saveAs($path)

    【讨论】:

      猜你喜欢
      • 2018-12-31
      • 1970-01-01
      • 2011-04-15
      • 1970-01-01
      • 2013-06-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多