upload photo in laravel
Below code for experience guys
I have used resize function before used you have to run the below command.
composer require intervention/image
then, open the config/app.php , Add below service provider in provider array :
'Intervention\Image\ImageServiceProvider'
Now add facade to aliases array.
'Image' => 'Intervention\Image\Facades\Image'
//now add code in controller
public function store(Request $request)
{
//resize image
$imgwidth = 100;
$imgheight = 100;
$folderupload = 'uploads/logo_banner';
$Dirpath = public_path($folderupload.'/'.$AdminId.'/'); //$AdminId is the user id
File::makeDirectory($Dirpath, $mode = 0777, true, true);
$file = $request->file('logo');
$filename = time() . $file->getClientOriginalName(); // prepend the time (integer) to the original file name
$path = $Dirpath . $filename;
// create instance of Intervention Image
$img = \Image::make($file->getRealPath());
if($img->width()>$imgwidth){
// See the docs - http://image.intervention.io/api/resize
// resize the image to a width of 300 and constrain aspect ratio (auto height)
$img->resize($imgwidth, $imgheight);
}
$img->save($path);
//
$Profile->photo = $filename;
}
}
Comments
Post a Comment