NotWritableException:无法将图像数据写入路径

NotWritableException: Can't write image data to path

我写这篇文章是为了将图片上传到 s3,我只在我的测试服务器上遇到这个错误,localhost 个人资料图片上传成功,没有收到错误。 php.ini 文件在 localhosttesting 环境中相同。还授予了 AWS 凭证。

在测试服务器代码执行到 if (!File::exists($folderPath)) { 据我所知,我写了那部分。这是代码。

                if ((strpos($profilePic, 'data:image/png;base64,') !== false)
                    || (strpos($profilePic, 'data:image/jpeg;base64,') !== false)) {

                    $img = Image::make($profilePic)->orientate();
                } else {
                    
                    $img = Image::make(base64_decode($profilePic))->orientate();
                }

                $original = 'avater.png';
                $small = 'avater_small.png';
                $medium = 'avater_medium.png';

                $folderPath = 'uploads/profile_pictures/'.$userId;

                $fullPath = $folderPath.'/'.$original;
                $fullPathSmall = $folderPath.'/'.$small;
                $fullPathMedium = $folderPath.'/'.$medium;
                
                if (!File::exists($folderPath)) {
                    File::makeDirectory($folderPath, 0775, true);
                }

                $smallImg = clone $img;
                $mediumImg = clone $img;

                if ($img->height() > $img->width()) {
                    // resize the image to a width of 300 and constrain aspect ratio          
                    $smallImg->resize(400, null, function ($constraint) {
                        $constraint->aspectRatio();
                    });

                    $mediumImg->resize(800, null, function ($constraint) {
                        $constraint->aspectRatio();
                    });
                } else {
                    // resize the image to a height of 200 and constrain aspect ratio
                    $smallImg->resize(null, 400, function ($constraint) {
                        $constraint->aspectRatio();
                    });

                    $mediumImg->resize(null, 400, function ($constraint) {
                        $constraint->aspectRatio();
                    });
                }

                $img->save($fullPath);
                $smallImg->save($fullPathSmall);
                $mediumImg->save($fullPathMedium);
                Storage::disk('s3')->put($fullPath, file_get_contents($profilePic), 'public');
                Storage::disk('s3')->put($fullPathMedium, file_get_contents($profilePic), 'public');
                Storage::disk('s3')->put($fullPathSmall, file_get_contents($profilePic), 'public');

                $user_repository = \App::make('App\Repositories\Contracts\UserRepositoryInterface');

                // $data = ['profile_image' => asset('uploads/profile_pictures/'.$userId.'/'.$original)];
                $data = ['profile_image' => '/uploads/profile_pictures/'.$userId.'/'.$original];

                $item_image = $user_repository->updateUser($userId,$data);

                return true;

您的测试服务器上的上传文件夹存在权限问题。请验证,因为在上传到 s3 存储桶之前,您首先将图像存储到上传文件夹。