简体   繁体   中英

Call to undefined method Intervention\Image\ImageManager::upload()

I am trying to upload an image into my database. When i do upload, i get this error below

Call to undefined method Intervention\\Image\\ImageManager::upload()

Searching on the internet for solutions, i found this method

adding this line 'Intervention\\Image\\ImageServiceProvider' in my $providers in config/app.php adding this line 'Image' => 'Intervention\\Image\\Facades\\Image' in my $aliases in config/app.php

In my controller as well, i have use Image. But then i am still getting this error above. What could i be missing please?

Controller

public function uploadImagePost(UploadUserImageRequest $request)
    {

        $user = Auth::user();

        $image = $request->file('profile_image');

        if (false === empty($user->image_path)) {
            $user->image_path->destroy();
        }

        $relativePath = 'uploads/users/' . $user->id;
        $path = $relativePath;


        $dbPath = $relativePath . DIRECTORY_SEPARATOR . $image->getClientOriginalName();

        $this->directory(public_path($relativePath));

        Img::upload($image, $path);

        $user->update(['image_path' => $dbPath]);

        return redirect()->route('my-account.home')
            ->with('notificationText', 'User Profile Image Uploaded successfully!!');
    }

Library you have used doesn't have upload() method. Use save() method for saving the file.

// read image from temporary file
$img = Image::make($_FILES['image']['tmp_name']);

// save image
$img->save('foo/bar.jpg');

Refer this link for more details

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM