首页 > 解决方案 > Laravel Jetstream 照片最大尺寸

问题描述

PHP 和 Laravel 的新手,但正在努力克服它。我正在使用带有 Jetstream 的 Laravel 8。现在,在前端的编辑部分中上传新的个人资料图片时,前端只接受 <1MB 的文件。

检查了我的 PHP.ini,它设置为 100M - 所以,通常它应该可以工作。任何想法,哪里可能有额外的验证或限制?

最佳皮埃尔

标签: laraveljetstream

解决方案


app\Actions\Fortify\UpdateUserProfileInformation.phpupdate()方法中,验证了您可以上传为个人资料图片的图像大小'photo' => ['nullable', 'image', 'max:1024']

见下面的方法:

public function update($user, array $input)
{
        
    Validator::make($input, [
        'name' => ['required', 'string', 'max:255'],
        'email' => ['required', 'email', 'max:255', Rule::unique('users')->ignore($user->id)],
        'photo' => ['nullable', 'image', 'max:1024'],
    ])->validateWithBag('updateProfileInformation');

    if (isset($input['photo'])) {
        $user->updateProfilePhoto($input['photo']);
    }

    if ($input['email'] !== $user->email &&
        $user instanceof MustVerifyEmail) {
        $this->updateVerifiedUser($user, $input);
    } else {
        $user->forceFill([
            'name' => $input['name'],
            'email' => $input['email'],
            'designation' => $input['designation'],
            'currentemployer' => $input['currentemployer'],
            'employementtype' => $input['employementtype'],
        ])->save();
    }
}

推荐阅读