Reputation: 1480
I'm getting a little confused here with this Storage VS Public paths in Laravel 5 > ... My understanding is one should use Storage::
instead of File::
for writing files to the Storage folder foresighting the use of cloud services like Amazon etc. So I am trying to put a jpg into a the storage/app
folder using Intervention and this code:
public function apply(Request $request)
{
$user = Auth::user();
$path = '/users/'.$user->id;
if (!Storage::exists($path))
{
Storage::makeDirectory ($path, $mode = 0755, $recursive = false, $force = false);;
}
Image::make($request->file('image'))
->orientate()
->resize(600, null, function ($constraint) {
$constraint->aspectRatio();
})
->resizeCanvas(600, 600, 'center', false, 'ffffff')
->save($path.'/foo.jpg');
}
First of all I am not sure the !Storage::exists($path)
will do anything as the API for storage tells it won't check for directories so how should I check if a Directory exists??
Second dd(is_writable($path))
; return false, and indeed running that code results in
NotWritableException in Image.php line 143:
Can't write image data to path
error. so how should this be done?
Upvotes: 0
Views: 1551
Reputation: 371
The "trick" that I used was manipulate the image directly in the temp path, and then save it in the storage folder using the Laravel storage method.
$tempFile = $request->file('image')->getRealPath();
Image::make($tempFile)
->resize(100, 100)
->save($tempFile); // Note that we are saving back to temporary path
// Now we can proceed and send the manipulated file to it's final destination
// in '/storage/app/public/uploads'
$path = $request->file('image')->storePublicly('public/uploads');
Upvotes: 1