I am trying to upload and resize an image in Laravel 5 and the Intervention library.
My code in the Controller is this:
// Upload img
if ($req->hasFile('img')) {
// Original
$image = Image::make(Input::file('img'));
// Mid sized
$image_mid = $image->fit(500,500, function($constraint) {
$constraint->upsize();
});
// Thumbnail
$image_thumb = $image->fit(100,100, function($constraint) {
$constraint->upsize();
});
// Path
$path = public_path('upload/artists/' . $id . '/profile/');
if (!File::exists($path)) {
File::makeDirectory($path . 'original', 0775, true, true);
File::makeDirectory($path . 'midsize', 0775, true, true);
File::makeDirectory($path . 'thumb', 0775, true, true);
}
// Save images
$image->save($path . 'original/' . $imgName);
$image_mid->save($path . 'midsize/' . $imgName);
$image_thumb->save($path . 'thumb/' . $imgName);
}
I am already trying to create de directories before moving the image, but it still gives me the same error, that I don't have permissions to move the image to that folder "NotWritableException".
Before using Intervention library, I was moving the image with the ->move() method and it was creating the directory if necessary.
I would really appreciate some help.. Thank you all in advance!
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire