Hello. I am using Laravel 5.2.
I am getting this error, when uploading image to the server:
Call to a member function getClientOriginalExtension() on a non-object
I have this line that casuses the issue:
$extension = $image->getClientOriginalExtension();
I am using intervention standard function to process image upload:
public function save(Request $request)
{
$image = $request->file('image');
$resizedImage = $this->resize($image, $request->get('image_size'));
if(!$resizedImage)
{
return redirect()->back()->withError('Could not resize Image');
}
return redirect()->route('image.resized')->with('image_url', asset('images/user_images'). '/' .$resizedImage->basename);
}
public function show()
{
$image_url = session('image_url');
return view('images.show', compact('image_url'));
}
private function resize($image, $size)
{
try
{
$extension = $image->getClientOriginalExtension();
$imageRealPath = $image->getRealPath();
$thumbName = 'thumb_'. $image->getClientOriginalName();
//$imageManager = new ImageManager(); // use this if you don't want facade style code
//$img = $imageManager->make($imageRealPath);
$img = Image::make($imageRealPath); // use this if you want facade style code
$img->resize(intval($size), null, function($constraint) {
$constraint->aspectRatio();
});
return $img->save(public_path('images/user_images'). '/'. $thumbName);
}
catch(Exception $e)
{
return false;
}
}
My form does have enctype="multipart/form-data" in the markup:
<form class="box" method="post" action="" enctype="multipart/form-data"> <!--this enctype is used to handle POST request with input type="file" -->
So I am trying to figure out what going on. the file name seems to show in the view when selecting it.
Would appreciate you help, thanks.