public function update() { $rules = array('name' => 'required', 'desc' => 'required', 'totalposts' => 'required|numeric'); $validator = Validator::make(Input::all(), $rules); $badgeid = Input::get('id'); if ($validator->fails()) { return Redirect::to('admin/editbadge/' . $badgeid)->withErrors($validator)->withInput(); } else { $name = Input::get('name'); if (Input::get('badge')) { $image = explode('/', Input::get('badge')); $image = urldecode(end($image)); $extension = explode(".", $image); $extension = end($extension); $img = Image::make('files/' . $image); $img->resize(160, null, function ($constraint) { $constraint->aspectRatio(); $constraint->upsize(); })->save('files/' . $image); $newname = date('YmdHis') . '_' . Str::slug($name, '_') . '.' . $extension; File::move('files/' . $image, 'badges/' . $newname); } $badge = Badge::find($badgeid); $badge->name = Input::get('name'); $badge->description = Input::get('desc'); if (Input::get('badge')) { $badge->image = $newname; } $badge->total_posts = Input::get('totalposts'); $badge->save(); Session::flash('success', 'Badge updated'); return Redirect::to('admin/badges'); } }
public static function boot() { parent::boot(); static::deleting(function ($photo) { $photo->galleries()->detach($photo->id); return true; }); static::deleted(function ($photo) { unlink(public_path() . \Config::get('laravel-photogallery::upload_dir') . '/' . $photo->path); $destination = public_path() . \Config::get('laravel-photogallery::upload_dir') . "/"; $formats = \Config::get('laravel-photogallery::formats'); foreach ($formats as $name => $format) { unlink($destination . $name . '/' . $photo->path); } }); static::created(function ($photo) { $destination = public_path() . \Config::get('laravel-photogallery::upload_dir') . "/"; $orig = $destination . $photo->path; $img = \Image::make($orig); $formats = \Config::get('laravel-photogallery::formats'); foreach ($formats as $name => $format) { $img->resize($format['w'], $format['h'], function ($constraint) { $constraint->aspectRatio(); }); $img->save($destination . $name . '/' . $photo->path, $format['q']); } }); }
public function store() { //存储数据 $market = new Market(); $market->title1 = $this->request->get('title1'); $market->sc_price = $this->request->get('sc_price'); $market->cb_price = $this->request->get('cb_price'); $market->desc = $this->request->get('desc'); $market->amount = $this->request->get('amount'); $market->rank = $this->request->get('rank'); $market->alibaba1 = $this->request->get('alibaba1'); $market->alibaba2 = $this->request->get('alibaba2'); $market->investigators = $this->request->get('investigators'); $market->save(); //获取图片 $images = $this->request->file('images'); foreach ($images as $image) { //获取图片名称 $fileName = md5(uniqid(str_random(10))); // try { \Image::make($image)->resize(100, 100)->save('uploads/images/' . $fileName . '.jpg'); //存储图片 $marketImage = new MarketImage(); $marketImage->image = 'uploads/images/' . $fileName . '.jpg'; $marketImage->market_id = $market->id; $marketImage->save(); } catch (\Exception $e) { //图片上传失败 dd($e->getMessage()); } } //通过循环存储照片 }
/** * Store a newly created resource in storage. * * @return Response */ public function store() { $id = Auth::user()->ID; $files = Input::file('files'); $assetPath = '/uploads/' . $id; $uploadPath = public_path($assetPath); $results = array(); foreach ($files as $file) { if ($file->getSize() > $_ENV['max_file_size']) { $results[] = array("name" => $file->getClientOriginalName(), "size" => $file->getSize(), "error" => "Please upload file less than " . $_ENV['max_file_size'] / 1000000 . "mb"); } else { //rename filename so that it won't overlap with existing file $extension = $file->getClientOriginalExtension(); $filename = time() . Str::random(20) . "." . $extension; // store our uploaded file in our uploads folder $name = $assetPath . '/' . $filename; $photo_attributes = array('name' => $filename, 'size' => $file->getSize(), 'url' => asset($name), 'user_id' => $id); $photo = new Photo($photo_attributes); if ($photo->save()) { if (!is_dir($uploadPath)) { mkdir($uploadPath, 0777); } //resize image into different sizes foreach (Photo::getThumbnailSizes() as $key => $thumb) { Image::make($file->getRealPath())->resize($thumb['width'], $thumb['height'])->save($uploadPath . "/" . $key . "-" . $filename); } //save original file $file->move($uploadPath, $filename); $results[] = Photo::find($photo->id)->find_in_json(); } } } // return our results in a files object return json_encode(array('files' => $results)); }
public function addProduct() { $id = \Input::get('id'); $rules = array('name' => 'required', 'quantity' => 'required|numeric', 'image' => 'image|mimes:jpeg,jpg,png,gif'); $input = \Input::all(); $valid = Validator::make($input, $rules); if ($valid->fails()) { return \Redirect::back()->withErrors($valid); } else { // If validation success $name = \Input::get('name'); $quantity = \Input::get('quantity'); $image = \Input::file('image'); $product = $id ? Products::find($id) : new Products(); // Creating product elobquent object // If image selected if ($image) { $filename = time() . "-" . $image->getClientOriginalName(); $path = 'assets/images/' . $filename; \Image::make($image->getRealPath())->resize(200, 200)->save($path); $existingImage = '/assets/images/' . $product->image; if (file_exists($existingImage)) { \File::delete($existingImage); } $product->image = $filename; } $product->name = $name; $product->quantity = $quantity; $product->save(); return redirect(action('ProductController@product')); } }
public function update($id) { if (Auth::id() != $id) { return Redirect::to('http://google.com'); } $user = Auth::User(); $validator = Validator::make(Input::all(false), ['email' => 'required|email|unique:users,email,' . $id, 'password' => 'min:5|confirmed:password_confirmation', 'first_name' => 'required', 'last_name' => 'required']); if ($validator->passes()) { $img_ava = $user->avatar_img; $password = Input::get('password'); if (Input::hasFile('avatar_img')) { if (File::exists(Config::get('user.upload_user_ava_directory') . $img_ava)) { File::delete(Config::get('user.upload_user_ava_directory') . $img_ava); } if (!is_dir(Config::get('user.upload_user_ava_directory'))) { File::makeDirectory(Config::get('user.upload_user_ava_directory'), 0755, true); } $img = Image::make(Input::file('avatar_img')); $img_ava = md5(Input::get('username')) . '.' . Input::file('avatar_img')->getClientOriginalExtension(); if ($img->width() < $img->height()) { $img->resize(100, null, function ($constraint) { $constraint->aspectRatio(); })->crop(100, 100)->save(Config::get('user.upload_user_ava_directory') . $img_ava, 90); } else { $img->resize(null, 100, function ($constraint) { $constraint->aspectRatio(); })->crop(100, 100)->save(Config::get('user.upload_user_ava_directory') . $img_ava, 90); } } $user->update(['username' => null, 'email' => Input::get('email'), 'password' => !empty($password) ? Hash::make($password) : $user->password, 'first_name' => Input::get('first_name'), 'last_name' => Input::get('last_name')]); return Redirect::back()->with('success_msg', Lang::get('messages.successupdate')); } else { return Redirect::back()->withErrors($validator)->withInput(); } }
/** * Upload the image while creating/updating records * @param File Object $file */ public function setImageAttribute($file) { // Only if a file is selected if ($file) { File::exists(public_path() . '/uploads/') || File::makeDirectory(public_path() . '/uploads/'); File::exists(public_path() . '/' . $this->images_path) || File::makeDirectory(public_path() . '/' . $this->images_path); File::exists(public_path() . '/' . $this->thumbs_path) || File::makeDirectory(public_path() . '/' . $this->thumbs_path); $file_name = $file->getClientOriginalName(); $file_ext = File::extension($file_name); $only_fname = str_replace('.' . $file_ext, '', $file_name); $file_name = $only_fname . '_' . str_random(8) . '.' . $file_ext; $image = Image::make($file->getRealPath()); if (isset($this->attributes['folder'])) { // $this->attributes['folder'] = Str::slug($this->attributes['folder'], '_'); $this->images_path = $this->attributes['folder'] . '/'; $this->thumbs_path = $this->images_path . '/thumbs/'; File::exists(public_path() . '/' . $this->images_path) || File::makeDirectory(public_path() . '/' . $this->images_path); File::exists(public_path() . '/' . $this->thumbs_path) || File::makeDirectory(public_path() . '/' . $this->thumbs_path); } if (isset($this->attributes['image'])) { // Delete old image $old_image = $this->getImageAttribute(); File::exists($old_image) && File::delete($old_image); } if (isset($this->attributes['thumbnail'])) { // Delete old thumbnail $old_thumb = $this->getThumbnailAttribute(); File::exists($old_thumb) && File::delete($old_thumb); } $image->save(public_path($this->images_path . $file_name))->fit(150, 150)->save(public_path($this->thumbs_path . $file_name)); $this->attributes['image'] = "{$this->attributes['folder']}/{$file_name}"; $this->attributes['thumbnail'] = "{$this->attributes['folder']}/thumbs/{$file_name}"; unset($this->attributes['folder']); } }
public function update($id) { $setting = Setting::findOrFail($id); $validator = Validator::make($data = Input::all(), Setting::$rules); if ($validator->fails()) { return Redirect::back()->withErrors($validator)->withInput(); } unset($data['logo']); // Logo Image Upload if (Input::hasFile('logo')) { $path = public_path() . "/assets/admin/layout/img/"; File::makeDirectory($path, $mode = 0777, true, true); $image = Input::file('logo'); $extension = $image->getClientOriginalExtension(); $filename = "logo.{$extension}"; $filename_big = "logo-big.{$extension}"; Image::make($image->getRealPath())->save($path . $filename); Image::make($image->getRealPath())->save($path . $filename_big); $data['logo'] = $filename; } $currencyArray = explode(':', $data['currency']); $data['currency'] = $currencyArray[1]; $data['currency_icon'] = $currencyArray[0]; $setting->update($data); Session::flash('success', '<strong>Success! </strong>Updated Successfully'); return Redirect::route('admin.settings.edit', 'setting'); }
public function store() { $rules = array("nombre" => "required", "descripcion" => "required"); $validator = Validator::make(Input::all(), $rules); if ($validator->fails()) { return Redirect::to("categoriasNegocios")->withErrors($validator)->withInput(Input::except("banner")); } else { $categoria = CategoriasNegocio::create(Input::all()); if (Input::hasFile('icono')) { $file = Input::file('icono'); $extension = $file->getClientOriginalExtension(); $name = $file->getClientOriginalName(); $name = basename($name, ".png"); $path = public_path() . '/img/emblemas/categorias'; $image = Image::make(Input::file('icono')->getRealPath()); $image->fit(96, 96); //3x $filename3x = $name . '@3x.' . $extension; $image->save($path . '/' . $filename3x); $categoria->icono_emblema = $filename3x; } $categoria->save(); } return Redirect::route('categoriasNegocios.show', $categoria->id); }
public function attachResize($w, $h, $crop = false) { try { $filename = $this->attachGetPath(); $resized_filename = str_replace($this->app['config']->get('attach.root'), $this->app['config']->get('attach.resized_path'), dirname($filename)) . DIRECTORY_SEPARATOR . $w . 'z' . $h . '_' . ($crop ? 'crop' : 'full') . '_' . basename($filename); if (!file_exists($resized_filename)) { \Log::info('resizing', ['browsify' => true]); $img = \Image::make($filename); if ($crop) { $img->fit($w, $h); } else { $img->resize($w, $h, function ($constraint) { $constraint->aspectRatio(); }); } if (!file_exists(dirname($resized_filename))) { $this->app['files']->makeDirectory(dirname($resized_filename), 0755, true, true); } $img->save($resized_filename); } return $resized_filename; } catch (\Exception $e) { return '/images/noimage.gif'; } }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(PostProductRequest $request) { if (!$request['category_id'] == '') { if (Auth::user()->role == 'free' && Auth::user()->product()->count() < $this->max_product_free) { $file = $request->file('image'); $extension = $file->getClientOriginalExtension(); $this->validate($request, ['image' => 'image']); $date = Carbon::now('America/Sao_Paulo'); $expired = $date->addMonth(); $product = Product::create(['category_id' => $request['category_id'], 'user_id' => $request['user_id'], 'name' => $request['name'], 'price' => $request['price'], 'expired_at' => $expired]); $filename = $product->slug . '-' . time() . '.' . $extension; $product->update(['image' => $filename]); \Image::make($file)->resize(253, 337)->save('uploads/products/253x337/' . $filename); \Image::make($file)->resize(450, 678)->save('uploads/products/450x678/' . $filename); Session::flash('message', 'Você cadastrou um produto com sucesso!'); return redirect()->route('dashboard.product.index'); } elseif (Auth::user()->role == 'standart' && Auth::user()->product()->count() < $this->max_product_standart) { $file = $request->file('image'); $extension = $file->getClientOriginalExtension(); $this->validate($request, ['image' => 'image']); $date = Carbon::now('America/Sao_Paulo'); $expired = $date->addMonth()->addMonth(); $product = Product::create(['category_id' => $request['category_id'], 'user_id' => $request['user_id'], 'name' => $request['name'], 'price' => $request['price'], 'expired_at' => $expired]); $filename = $product->id . '-' . $product->slug . '-' . time() . '.' . $extension; $product->update(['image' => $filename]); Storage::disk('public_local')->put($filename, File::get($file)); Session::flash('message', 'Você cadastrou um produto com sucesso!'); return redirect()->route('dashboard.product.index'); } elseif (Auth::user()->role == 'premium' && Auth::user()->product()->count() < $this->max_product_premium) { $file = $request->file('image'); $extension = $file->getClientOriginalExtension(); $this->validate($request, ['image' => 'image']); $date = Carbon::now('America/Sao_Paulo'); $expired = $date->addMonth()->addMonth()->addMonth(); $product = Product::create(['category_id' => $request['category_id'], 'user_id' => $request['user_id'], 'name' => $request['name'], 'price' => $request['price'], 'featured' => '1', 'expired_at' => $expired]); $filename = $product->id . '-' . $product->slug . '-' . time() . '.' . $extension; $product->update(['image' => $filename]); Storage::disk('public_local')->put($filename, File::get($file)); Session::flash('message', 'Você cadastrou um produto com sucesso!'); return redirect()->route('dashboard.product.index'); } elseif (Auth::user()->role == 'admin') { $file = $request->file('image'); $extension = $file->getClientOriginalExtension(); $this->validate($request, ['image' => 'image']); $date = Carbon::now('America/Sao_Paulo'); $expired = $date->addMonth(); $product = Product::create(['category_id' => $request['category_id'], 'user_id' => $request['user_id'], 'name' => $request['name'], 'price' => $request['price'], 'expired_at' => $expired]); $filename = $product->id . '-' . $product->slug . '-' . time() . '.' . $extension; $product->update(['image' => $filename]); Storage::disk('public_local')->put($filename, File::get($file)); Session::flash('message', 'Você cadastrou um produto com sucesso!'); return redirect()->route('dashboard.product.index'); } else { Session::flash('error', "Você não pode cadastrar mais produtos!"); return redirect()->route('dashboard.home'); } } Session::flash('error', 'Você não pode cadastrar um produto sem categoria!'); return redirect()->route('dashboard.product.index'); }
/** * Store a newly created resource in storage. * * @return Response */ public function store($gallery_id) { $input = \Input::all(); $validation = new \Itestense\LaravelPhotogallery\Validators\Photo(); if ($validation->passes()) { $filename = str_random(10) . time() . "." . \Input::file('path')->getClientOriginalExtension(); $destination = public_path() . \Config::get('upload_dir') . "/"; $upload = \Input::file('path')->move($destination, $filename); $img = \Image::make($destination . $filename); $formats = \Config::get('laravel-photogallery::formats'); foreach ($formats as $name => $format) { $img->resize($format['w'], $format['h'], function ($constraint) { $constraint->aspectRatio(); }); $img->save($destination . $name . '/' . $filename, $format['q']); } if ($upload == false) { return \Redirect::to('gallery.photo.create')->withInput()->withErrors($validation->errors)->with('message', 'Errori'); } $photo = new Photo(); $photo->name = \Input::get('name'); $photo->description = \Input::get('description'); $photo->path = $filename; $photo->save(); $g = Gallery::findOrFail(1); $photo->galleries()->attach($g); //return \Redirect::route("gallery.photo.show", array('id' => $photo->id)); } else { return \Redirect::route('gallery.photo.create')->withInput()->withErrors($validation->errors)->with('message', \Lang::get('gallery::gallery.errors')); } }
public function update(Request $request) { $id = Auth::user()->id; $user = User::findOrFail($id); $this->validate($request, ['name' => 'min:5', 'email' => 'min:5', 'image' => 'mimes:jpg,jpeg,png|max:1000']); $input['name'] = $request->get('name'); $input['email'] = $request->get('email'); if ($request->file('image') != NULL) { $image_extension = $request->file('image')->getClientOriginalExtension(); $image_name = $id; $input['avatar'] = $image_name . '.' . $image_extension; $destinationFolder = '/admin/assets/images/avatar/'; $destinationThumbnail = '/admin/assets/images/avatar/thumbs/'; if (isset($user->avatar)) { $avatars = array(public_path() . $destinationFolder . $user->avatar, public_path() . $destinationThumbnail . $user->avatar); \File::delete($avatars); } $user->fill($input)->save(); $file = \Input::file('image'); $image = \Image::make($file->getRealPath()); $image->save(public_path() . $destinationFolder . $image_name . '.' . $image_extension)->resize(60, 60)->save(public_path() . $destinationThumbnail . $image_name . '.' . $image_extension); } $user->update($input); \Session::flash('flash_message', 'Профилът ви беше успешно редактиран!'); return redirect()->route('admin.user.edit'); }
public function postCreate() { $validator = Validator::make(Input::all(), Car::$rules); if ($validator->passes()) { $car = new Car(); $car->type_id = Input::get('type_id'); $car->title = Input::get('title'); if (Input::get('description')) { $car->description = Input::get('description'); } $car->price = Input::get('price'); $car->available_at = Input::get('available_at'); $car->transmission = Input::get('transmission'); $car->aircon = Input::get('aircon'); $car->seats = Input::get('seats'); $car->doors = Input::get('doors'); $image = Input::file('image'); $filename = date('Y-m-d-H:i:s') . "-" . $image->getClientOriginalName(); Image::make($image->getRealPath())->resize(220, 128)->save('public/img/cars/' . $filename); $car->image = 'img/cars/' . $filename; $car->save(); return Redirect::to('admin/cars/index')->with('message', 'New Car Added'); } return Redirect::to('admin/cars/index')->with('message', 'Something went wrong')->withErrors($validator)->withInput(); }
/** * Store a newly created resource in storage. * * @return Response */ public function store(Request $request) { $validator = Validator::make($request->all(), ['desc' => 'required', 'desc2' => 'required', 'image' => 'required', 'onlymembers' => 'required', 'img_album_id' => 'required']); if ($validator->fails()) { return Redirect::back()->withErrors($validator)->withInput(); } else { $newImg = new Img(); $newImg->desc = $request->input('desc'); $newImg->desc2 = $request->input('desc2'); $newImg->onlymembers = $request->input('onlymembers'); $newImg->img_album_id = $request->input('img_album_id'); $album = ImgAlbum::findOrFail($newImg->img_album_id); $file = $request->file('image'); $image = \Image::make($request->file('image')); if ($file != null) { if ($file->isValid()) { $name = $newImg->desc . '.' . $file->getClientOriginalExtension(); $path = 'img/album/' . $album->id; $file->move($path, $name); $image->fit(100, 50); $image->save($path . '/thumb/' . $name); $newImg->imgurl = $name; } else { //dd ('Imagen invalida'); } } else { // dd ('No hay Imagen'); } $newImg->save(); } Session::flash('message', 'Album creado correctamente'); return Redirect::to('/administration/image'); }
/** * Display a listing of the resource. * GET /image * * @return Response */ public function crop() { $imgUrl = Input::get('imgUrl'); $imgInitW = Input::get('imgInitW'); $imgInitH = Input::get('imgInitH'); $imgW = Input::get('imgW'); $imgH = Input::get('imgH'); $imgY1 = intval(Input::get('imgY1')); $imgX1 = intval(Input::get('imgX1')); $cropW = intval(Input::get('cropW')); $cropH = intval(Input::get('cropH')); $url = Input::get('url'); $path_parts = pathinfo($imgUrl); //return $url.$imgUrl; //return $cropW.' '.$cropH.' '.$imgX1.' '.$imgY1; $filename = time() . "-profile_pic." . $path_parts['extension']; $path = public_path('img/avatar/' . $filename); $img = Image::make($url . $imgUrl); $img->resize($imgW, $imgH)->crop($cropW, $cropH, $imgX1, $imgY1)->save($path, 100); $img->destroy(); File::delete(public_path() . $imgUrl); // crop image $response = array("status" => 'success', "url" => "/img/avatar/" . $filename, "file" => File::exists(public_path() . $imgUrl), "origin" => $imgUrl); return json_encode($response); }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { //save inputan $input = Input::all(); $low = new Berita(); $low->judul = $input['judul']; $low->deskripsi = $input['deskripsi']; $low->save(); //get last Id $lastIdLow = Berita::orderBy('id', 'desc')->select('id')->take(1)->get(); $lastId = $lastIdLow[0]['id']; if (Input::file('file_upload')) { $watermark = \Image::make(public_path() . '/imagesBerita/sample.png'); //upload images $destinationPath = public_path() . '/imagesBerita/'; $extension = Input::file('file_upload')->getClientOriginalExtension(); $fileName = "Berita." . "{$lastId}." . $extension; $cek = Input::file('file_upload')->move($destinationPath, $fileName); $image = \Image::make($destinationPath . $fileName); $image->insert($watermark, 'center'); $image->save(); //edit field path $namaPath = Berita::find($lastId); $namaPath->path = $fileName; $namaPath->save(); } return Redirect::to("/adminBerita"); }
/** * @param $file * @return array */ public function upload($file) { if (!$file->getClientOriginalName()) { return ['status' => false, 'code' => 404]; } $destinationPath = public_path() . $this->imgDir; $fileName = $file->getClientOriginalName(); $fileSize = $file->getClientSize(); $ext = $file->guessClientExtension(); $type = $file->getMimeType(); $upload_success = Input::file('file')->move($destinationPath, $fileName); if ($upload_success) { $md5_name = md5($fileName . time()) . '.' . $ext; $_uploadFile = date('Ymd') . '/' . $md5_name; if (!File::isDirectory($destinationPath . date('Ymd'))) { File::makeDirectory($destinationPath . date('Ymd')); } // resizing an uploaded file Image::make($destinationPath . $fileName)->resize($this->width, $this->height)->save($destinationPath . $_uploadFile); File::delete($destinationPath . $fileName); $data = ['status' => true, 'code' => 200, 'file' => ['disk_name' => $fileName, 'file_name' => $md5_name, 'type' => $type, 'size' => $fileSize, 'path' => $this->imgDir . $_uploadFile]]; return $data; } else { return ['status' => false, 'code' => 400]; } }
public function upload($file, $directory) { $filename = $file->getClientOriginalName(); $path = \Config::get('image.upload_path') . $directory . "/"; $url = "/uploads/" . $directory . "/" . $filename; $dest_file = $path . $filename; $ext = strtolower($file->getClientOriginalExtension()); $dimensions = \Config::get('image.dimensions'); $file->move($path, $filename); $paths = array(); $paths['orignal'] = $url; foreach ($dimensions as $key => $dimension) { // Get dimmensions and quality $width = (int) $dimension[0]; $height = (int) $dimension[1]; $crop = (bool) $dimension[2]; // Run resizer $image = \Image::make($dest_file); if ($crop) { $image = $image->grab($width, $height); } else { $image = $image->resize($width, $height, true, false); } $paths[$key] = "/uploads/" . $directory . "/" . basename($filename, '.' . $ext) . $width . 'x' . $height . '.' . $ext; $image->save($path . basename($filename, '.' . $ext) . $width . 'x' . $height . '.' . $ext); } $this->path = json_encode($paths); }
public function getImage() { if (!Input::hasFile('photo')) { return \Redirect::back(); } $file = Input::file('photo'); $file->move(public_path() . '/uploads', $file->getClientOriginalName()); $image = \Image::make(sprintf(public_path() . '/uploads/%s', $file->getClientOriginalName()))->resize(120, 120)->save(); return Redirect::back(); // // Make a new response out of the contents of the file // // We refactor this to use the image resize function. // // Set the response status code to 200 OK // $response = Response::make( // Image::resize($filename, $size), // 200 // ); // // Set the mime type for the response. // // We now use the Image class for this also. // $response->header( // 'content-type', // Image::getMimeType($filename) // ); // // We return our image here. // return $response; }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $image = Input::file('image'); $filename = time() . '.' . $image->getClientOriginalExtension(); $path = public_path('uploads/img/' . $filename); Image::make($image->getRealPath())->resize(200, 200)->save($path); $user->image = $filename; $user->save(); $obj = new helpers(); echo "<pre>"; print_r(Input::file('image')); exit; $book = Request::all(); //echo "<pre>";print_r($_FILES['image']['name']);exit; $destinationPath = 'uploads/img/'; // upload path $thumb_path = 'uploads/img/thumb/'; $extension = Input::file('image')->getClientOriginalExtension(); // getting image extension $fileName = rand(111111111, 999999999) . '.' . $extension; // renameing image Input::file('image')->move($destinationPath, $fileName); // uploading file to given path $obj->createThumbnail($fileName, 300, 200, $destinationPath, $thumb_path); $book['image'] = $fileName; Book::create($book); Session::flash('success', 'Upload successfully'); return redirect('image'); }
/** * Store a newly created resource in storage. * * @return Response */ public function store() { $file = Input::file('file'); $filename = $file->getClientOriginalName(); if ($file) { $filename = $file->getClientOriginalName(); $extension = $file->getClientOriginalExtension(); $destinationPath = public_path() . '/uploads/original/'; $destinationPath_big = public_path() . '/uploads/big/'; $destinationPath_crop = public_path() . '/uploads/crop/'; $upload_success = Input::file('file')->move($destinationPath, $filename); if ($upload_success) { $image = Image::make($destinationPath . $filename)->resize(800, null, true)->save($destinationPath_big . $filename); $image = Image::make($destinationPath . $filename)->resize(640, null, true)->crop(400, 300, true)->save($destinationPath_crop . $filename); File::delete($destinationPath . $filename); $arch = new Archivo(); $arch->archivo = $filename; $arch->descripcion = Input::get('descripcion', ''); $arch->padre_id = Input::get('padre_id'); $arch->padre = Input::get('padre'); $arch->save(); } return Redirect::to('/articulos/ver'); } }
/** * Store a newly created resource in storage. * * @return Response */ public function store() { $imageName = ''; $imagePath = public_path() . '/img/'; if (Input::hasFile('photo')) { $img = Input::file('photo'); $imageName = str_random(6) . '_' . $img->getClientOriginalName(); $img->move($imagePath, $imageName); $img = Image::make($imagePath . $imageName); $img->save($imagePath . $imageName); $thumb = Image::make($imagePath . $imageName); $thumbName = $imageName; $thumbPath = public_path() . '/thumbs/img/'; $thumb->resize(100, 100); $thumb->save($thumbPath . $thumbName); $imgEntry = new Photo(); $imgEntry->user_id = Auth::user()->id; $imgEntry->caption = Input::get('caption'); $imgEntry->path = 'img/' . $imageName; $imgEntry->save(); return Response::json(array('error' => false, 'message' => 'Upload successful.'), 200); } else { return Response::json(array('error' => 'true', 'photos' => null), 200); } }
public function updateCapture(Request $request, $id) { $this->validate($request, ['pokemon' => 'required|exists:pokemon,id', 'photo' => 'image']); // Get info on the capture $capture = Capture::findOrFail($id); if ($request->hasFile('photo')) { // Generate a new file name $fileName = uniqid() . '.' . $request->file('photo')->getClientOriginalExtension(); \Image::make($request->file('photo'))->resize(320, null, function ($constraint) { $constraint->aspectRatio(); })->save('img/captures/' . $fileName); // Delete the old image \File::Delete('img/captures/' . $capture->photo); $capture->photo = $fileName; } if (\Carbon\Carbon::now()->diffInDays($capture->updated_at) > 5) { if ($capture->attack < 350) { $capture->attack += rand(0, 10); if ($capture->attack > 350) { $capture->attack = 350; } } if ($capture->defense < 350) { $capture->defense += rand(0, 10); if ($capture->defense > 350) { $capture->defense = 350; } } } $capture->pokemon_id = $request->pokemon; $capture->save(); return redirect('pokecentre/captures'); }
/** * [updatePhoto description] * @param Integer Id do usuário * @return ?? */ public function cropPhotoEntidade($entidade, CropPhotoRequest $request) { if (!$entidade) { App::abort(500, 'Erro durante o processamento do crop'); } $file = Input::file('image_file_upload'); if ($file && $file->isValid()) { $widthCrop = $request->input('w'); $heightCrop = $request->input('h'); $xSuperior = $request->input('x'); $ySuperior = $request->input('y'); $destinationPath = public_path() . '/uploads/'; $extension = Input::file('image_file_upload')->getClientOriginalExtension(); // Pega o formato da imagem $fileName = self::formatFileNameWithUserAndTimestamps($file->getClientOriginalName()) . '.' . $extension; $file = \Image::make($file->getRealPath())->crop($widthCrop, $heightCrop, $xSuperior, $ySuperior); $upload_success = $file->save($destinationPath . $fileName); //Salvando imagem no avatar do usuario; if ($upload_success) { /* Settando tipo da foto atual para null, checando se existe antes */ if ($entidade->avatar) { $currentAvatar = $entidade->avatar; $currentAvatar->tipo = null; $currentAvatar->save(); } $foto = new Foto(['path' => $fileName, 'tipo' => 'avatar']); $entidade->fotos()->save($foto); return true; } else { return false; } } }
public function updatePhoto(Photo $photo) { $inputs = ['photo' => Input::file('photo'), 'description' => Input::get('description'), 'user_id' => Input::get('uid'), 'album_id' => Input::get('album_id'), 'name' => Input::get('tag')]; $attributeNames = ['name' => 'Tag name']; $valid = Validator::make($inputs, Photo::$rulesEdit); $valid->setAttributeNames($attributeNames); $valid->sometimes('name', 'unique:tags|min:3|max:12', function ($inputs) { return !is_numeric($inputs['name']); }); if ($valid->passes()) { $photo->description = $inputs['description']; $photo->user_id = $inputs['user_id']; $photo->album_id = $inputs['album_id']; $tag = $inputs['name']; if (isset($inputs['photo'])) { $image = $inputs['photo']; //$filename = $this->getImagePath($image->getClientOriginalName()); Image::make($image->getRealPath())->save(storage_path() . '/photos/' . $filename); $photo->image = $filename; } if ($tag != 'default') { $photo->addTagOrCreateNew($tag, $inputs['user_id']); } $photo->save(); return Redirect::back()->with('success', Lang::choice('messages.Photos', 1) . ' ' . trans('messages.is updated')); } else { return Redirect::back()->withErrors($valid)->withInput(); } }
public function update($id, Request $request) { $validator = Validator::make($request->all(), ['first_name' => 'required', 'last_name' => 'required']); if ($validator->fails()) { $messages = $validator->messages(); return Redirect::back()->withErrors($validator)->withInput(); } else { \DB::statement('SET FOREIGN_KEY_CHECKS = 0'); $supplier = Supplier::find($id); $supplier->fill($request->except('_token')); $supplier->parent_id = 0; if ($request->password != '') { $supplier->password = Hash::make($request->password); } if (Input::hasFile('profileimage')) { $file = Input::file('profileimage'); $imagename = time() . '.' . $file->getClientOriginalExtension(); if (\File::exists(public_path('upload/supplierprofile/' . $supplier->image))) { \File::delete(public_path('upload/supplierprofile/' . $supplier->image)); } $path = public_path('upload/supplierprofile/' . $imagename); $image = \Image::make($file->getRealPath())->save($path); $th_path = public_path('upload/supplierprofile/thumb/' . $imagename); $image = \Image::make($file->getRealPath())->resize(128, 128)->save($th_path); $supplier->image = $imagename; } $supplier->save(); \DB::statement('SET FOREIGN_KEY_CHECKS = 1'); return Redirect::route('supplier_master_list')->with('succ_msg', 'Supplier has been created successfully!'); } }
/** * Update the specified resource in storage. * @param SettingsFormRequest $request * @param $id * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector */ public function update(SettingsFormRequest $request, $id) { $setting = $this->setting->getById($id); $data = array('name' => $request->name, 'email' => $request->email, 'contact' => $request->contact, 'phone' => $request->phone, 'address1' => $request->address1, 'address2' => $request->address2, 'city' => $request->city, 'state' => $request->state, 'country' => $request->country, 'postal_code' => $request->postal_code, 'vat' => $request->vat, 'website' => $request->website, 'date_format' => $request->date_format); if ($request->hasFile('logo')) { $file = $request->file('logo'); $filename = strtolower(str_random(50) . '.' . $file->getClientOriginalExtension()); $file->move('assets/img', $filename); \Image::make(sprintf('assets/img/%s', $filename))->resize(200, 200)->save(); \File::delete('assets/img/' . $setting->logo); $data['logo'] = $filename; } if ($request->hasFile('favicon')) { $file = $request->file('favicon'); $filename = 'favicon.' . $file->getClientOriginalExtension(); $file->move('assets/img', $filename); \Image::make(sprintf('assets/img/%s', $filename))->resize(16, 16)->save(); $data['favicon'] = $filename; } if ($this->setting->updateById($id, $data)) { flash()->success('System Settings updated'); } else { flash()->error('Error occurred while updating system Settings, try again'); } return redirect('settings/company'); }
/** * [imgExist Check if the img exist, if exist and $size is charge, make the thumb if it dont exist] * @param [type] $path [image Relative path] * @param [type] $file [image file name] * @param array $size [size of thumb] * @return [String or false] [route of the img or false] */ private function imgExist($path, $file, $size = []) { if (count($size)) { $w = isset($size['w']) ? $size['w'] : false; $h = isset($size['h']) ? $size['h'] : false; $ext = explode('.', $file); $ext = $ext[count($ext) - 1]; $name = rtrim($file, '.' . $ext); $pathFile = $path . "/" . $name . ($w ? '_w' . $w : '') . ($h ? '_h' . $h : '') . '.' . $ext; } else { $pathFile = "{$path}/{$file}"; } if (!file_exists($pathFile) || !is_file($pathFile)) { if (file_exists("{$path}/{$file}") && is_file("{$path}/{$file}") && count($size)) { $img = \Image::make("{$path}/{$file}")->resize($w ? $w : null, $h ? $h : null, function ($constraint) { $constraint->aspectRatio(); $constraint->upsize(); }); $img->save($pathFile); return $pathFile; } return false; } return $pathFile; }
/** * Execute the job. * * @return void */ public function handle() { //dd($this->req); try { \DB::begintransaction(); $parent_id = empty($this->req['parent_id']) ? 0 : $this->req['parent_id']; $file = ''; if (!empty($_FILES['feed_file']['tmp_name'])) { $base_name = date('d_m_Y_') . md5($_FILES['feed_file']['name']) . rand(11111, 99999) . time(); $fl_name = $base_name . '.png'; $fl = file_get_contents($_FILES['feed_file']['tmp_name']); \Image::make($fl)->save($this->path . $fl_name); $file = $fl_name; } $feed = data_feedback::create(['title' => $this->req['feed_title'], 'ask' => $this->req['feed_ask'], 'link' => $this->req['feed_link'], 'parent_id' => $parent_id, 'file' => $file, 'id_karyawan' => \Me::data()->id_karyawan]); $kode = \Format::code($feed->id_feedback); $feed->kode = $kode; $feed->save(); if ($parent_id > 0) { $up = data_feedback::find($parent_id); $up->notif = $up->notif + 1; $up->save(); } \Loguser::create('Megisi form feedback Kode. #' . $kode); \DB::commit(); return ['label' => 'success', 'err' => 'Feedback berhasil terkirim dengan Kode. ' . $feed->kode]; } catch (\Exception $e) { \DB::rollback(); if (file_exists($this->path . $file)) { @unlink($this->path . $file); } return ['label' => 'danger', 'err' => $e->getMessage()]; } }