'Laravel image intervention unable to init from given url
Good evening, i hosted a Laravel project and found some bug. First of all, here is my code in my controller:
$request->file('FotoHT')->storeAs('FotoHT', $filenameToStore); //this is to safe
$path = asset('storage/app/FotoHT/'. $filenameToStore);
$width = Image::make($path)->width();
$height = Image::make($path)->height();
I save a picture, and it works but when i try using
Image::make($path)->width();
it give me the wrong url. It give me
https://myweb/public/storage/app/FotoHT/_MG_9549_1578913993.jpg
while the image should be accessed from
https://myweb/storage/app/FotoHT/_MG_9549_1578913993.jpg
Can anyone give me a help/solution?
Solution 1:[1]
You need to save the image encode to the public path
$fieldFile = $request->file('FotoHT');
$image = Image::make($fieldFile)->width();
Storage::disk('public')->put("FotoHT/".$filenameToStore, (string) $image->encode());
Solution 2:[2]
$path=$request->file('FotoHT')->storeAs('FotoHT',$filenameToStore);
$width = Image::make($path)->width();
$height = Image::make($path)->height();
Try this command.You can use asset() helper method for img tag in view
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | ?lker Özer |
