public function addPicture($brand_id) { $file = Request::file('file'); $extension = $file->getClientOriginalExtension(); $path = 'brand/' . $brand_id . '/'; $filename = $file->getFilename() . '.' . $extension; $fileStorage = new FileStorageController(); $fileStorage->saveImage($path, $filename, $file); $entry = new Fileentry(); $entry->mime = $file->getClientMimeType(); $entry->original_filename = $file->getClientOriginalName(); $entry->filename = $file->getFilename() . '.' . $extension; $entry->path = $path . $filename; $entry->save(); // now the image is saved //now we need to attach this image to our brand; $brand_image = new BrandImage(); $brand_image->brand_id = $brand_id; $brand_image->fileentry_id = $entry->id; $brand_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' => false, 'code' => 200], 200); }
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); }