storeAs is an UploadedFile method https://laravel.com/docs/9.x/filesystem#specifying-a-file-name
Intervention Image has save https://image.intervention.io/v2/api/save
Hi everybody, before storing a file on my laravel app I want to proccess the image with Intervention package, and then upload it to my public disc using method storeAs as always, however I'm getting the following error:
Command (StoreAs) is not available for driver (Gd).
My upload method:
public function uploadAndProccess( $request, $name, $previousImage = false , $folder = 'uploads')
{
if ($request->hasFile($name))//&& $request->file($name)->isValid())
{
$image = $request->file($name);
$extension = $image->guessExtension();
$resized = Image::make($image)->resize(640, null, function ($constraint) {
$constraint->aspectRatio();
$constraint->upsize(); })
->encode('jpg',75);
//->stream();
$file = $resized;
$filename = 'file-'.Carbon::now()->format('d-m-Y-H-i').'-'.Str::random(3).'-'.mt_rand('000','999').'.'.$extension;
$file->storeAs('uploads', $filename);
if($previous)
{
File::delete($filename);
}
return $folder.$filename;
}
else
{
return $previousImage;
}
}
@Gabotronix what do you think the error message means? You are trying to write to an uploads directory in the root in the filesystem rather than the public directory! And you're not using the $filename you created!
Let's simplify this:
$extension = $image->guessExtension();
$resized = Image::make($request->file($name))->resize(640, null, function ($constraint) {
$constraint->aspectRatio();
$constraint->upsize();
})->encode('jpg',75);
$filename = 'file-'.Carbon::now()->format('d-m-Y-H-i').'-'.Str::random(3).'-'.mt_rand('000','999').'.'.jpg;
$resized->save(public_path("uploads/{$filename}"));
Please or to participate in this conversation.