谁一开始就是大神?

yii2自带的UploadedFile,怎么查看他的出错原因啊?[2.0]

在本地Windows测试环境是没有问题的,但上传到Linux上就出问题了
controller代码:

$model = new UserUploadForm();
		if(Yii::$app->request->isPost){var_dump(UploadedFile::getInstance($model, 'user_image'));exit;
			$model->user_image = UploadedFile::getInstance($model, 'user_image');
            if ($model->upload()) {
                Yii::$app->session->setFlash('success', '用户头像修改成功');
				return $this->refresh();
            }else{
				Yii::$app->session->setFlash('error', '用户头像修改失败');
				return $this->refresh();
			}
		}

模型代码:

public $user_image;
	public function rules()
    {
        return [
			['user_image','required'],
			[['user_image'], 'file', 'skipOnEmpty' => false, 'extensions' => 'png, jpg'],
        ];
    }
	public function attributeLabels(){
		return [
			'user_image'	=>	'用户头像',	
		];
	}
	public function upload()
    {
        if ($this->validate()) {
			$path		=	'uploads/avatar/' . time() . '.' . $this->user_image->extension;
            $this->user_image->saveAs($path);
			$user		=	User::findOne(\Yii::$app->user->id);
			$user->user_image	=	'/'.$path;
			if($user->update()!==false){
				return true;
			}
            return false;
        } else {
            return false;
        }
    }

在controller里面我用var_dump()测试了一下,在本地上展示的结果为:
object(yii\web\UploadedFile)[103]
public ‘name’ => string ‘1449301410.png’ (length=14)
public ‘tempName’ => string ‘J:\wamp\tmp\phpBC98.tmp’ (length=23)
public ‘type’ => string ‘image/png’ (length=9)
public ‘size’ => int 2744986
public ‘error’ => int 0
在Linux上展示的结果为:
object(yii\web\UploadedFile)#103 (5) { [“name”]=> string(14) “1449301410.png” [“tempName”]=> string(0) “” [“type”]=> string(0) “” [“size”]=> int(0) [“error”]=> int(1) }
请问是什么原因?或者可以直接告诉我怎么查看出错原因

根据你错误信息来看 上传文件过大了,
检查一下 服务器php配置参数upload_max_filesize

赞(0) 打赏
未经允许不得转载:菜鸟之家 » yii2自带的UploadedFile,怎么查看他的出错原因啊?[2.0]

评论 抢沙发

登录

找回密码

注册