Level 18
Solved it, changed the thumb storage to: $background->save(base_path().'/storage/app/project/'. $id .'/thumb_'. $name);
Hi guys,
I'm having a weird situation here, using the Storage::put command i successfully upload files to my project. When i check the directory with my FTP client, the mail files are actually uploaded and seem to work fine, however, the uploading script still gives me errors when generation the thumbnails saying:
NotWritableException in Image.php line 138:
Can't write image data to path (../storage/app/project/3/thumb_1436516849_195ec28ba61123ed4c4199cbb6a6dbac.jpg)
So i assume it has to with the path? my code to upload is:
if (Request::hasFile('attachments'))
{
foreach (Request::file('attachments') as $file)
{
if ($file->isValid())
{
$fileName = time() .'_'. md5($file->getClientOriginalName()) .'.'. $file->getClientOriginalExtension();
Storage::put('project/'. $id .'/'. $fileName, file_get_contents($file));
ProjectAttachment::create(['project_id' => $id, 'name' => $fileName]);
if (substr(File::mimeType($file), 0, 5) == 'image')
{
$this->attachmentThumb(file_get_contents($file), $id, $fileName, 100, 100);
}
}
}
}
public function attachmentThumb($input, $id, $name, $width, $height)
{
// create new image with transparent background color
$background = Image::canvas($width, $height);
// read image file and resize it
// but keep aspect-ratio and do not size up,
// so smaller sizes don't stretch
$image = Image::make($input)->resize($width, $height, function ($c) {
$c->aspectRatio();
$c->upsize();
});
// insert resized image centered into background
$background->insert($image, 'center');
// save
$background->save('../storage/app/project/'. $id .'/thumb_'. $name);
}
What am i doing wrong here?
Solved it, changed the thumb storage to: $background->save(base_path().'/storage/app/project/'. $id .'/thumb_'. $name);
Please or to participate in this conversation.