Beispiel #1
0
 public function addPicture($article_id)
 {
     $file = Request::file('file');
     $extension = $file->getClientOriginalExtension();
     $path = 'article/' . $article_id . '/';
     $filename = $file->getFilename() . '.' . $extension;
     $thumb_filename = $file->getFilename() . '_thumb.' . $extension;
     $fileStorage = new FileStorageController();
     $fileStorage->saveImage($path, $filename, $file);
     $fileStorage->saveThumbnail($path, $thumb_filename, $file, 320, 150);
     $entry = new Fileentry();
     $entry->mime = $file->getClientMimeType();
     $entry->original_filename = $file->getClientOriginalName();
     $entry->filename = $file->getFilename() . '.' . $extension;
     $entry->path = $path . $filename;
     $entry->thumbnail_path = $path . $thumb_filename;
     $entry->save();
     // now the image is saved
     //now we need to attach this image to our brand;
     $article_image = new ArticleImage();
     $article_image->article_id = $article_id;
     $article_image->fileentry_id = $entry->id;
     $article_image->save();
     // Because this will be called via Ajax by DropZone
     // The response must be in JSON
     // - this is a 200 OK success
     return Response::json(['error' => 'File could not be saved!', 'code' => 200], 200);
 }