Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function store()
- {
- try {
- $valid = Validator::make(Request::all(), [
- 'pics' => '',
- 'title' => '',
- ]);
- if ($valid->passes()) {
- if (request::hasFile('pics')) {
- $files = request::file('pics');
- foreach ($files as $file)
- {
- $validator2 = Validator::make(array('file' => $file), ['file' => 'image|mimes:png,gif,jpeg,jpg|max:5000']);
- if ($validator2->fails()) {
- return redirect()->back()->withInput()->withErrors($validator2->messages());
- }
- }
- }
- $tran = DB::transaction(function() {
- $product = new ImageGallery;
- $product->user_id = Sentry::getUser()->id;
- $product->title = Security::xss_clean(Input::get('title'));
- $product->description = Security::xss_clean(Input::get('description'));
- $product->created_at = jDate::forge()->time();
- $insertedProduct = $product->id;
- if (request::hasFile('pics')) {
- $files = request::file('pics');
- foreach ($files as $file) {
- $destinationPath = 'uploads/gallery';
- $filename = $file->getClientOriginalName();
- $extension = $file->getClientOriginalExtension();
- $filename = sha1($filename) . '-' . rand(1000, 9999) . '.' . $extension;
- $upload_success = $file->move($destinationPath, $filename);
- if ($upload_success)
- {
- $img = Image::make($destinationPath . '/' . $filename);
- //$watermark = Image::make('logo.png');
- //$img->insert($watermark, 'bottom-right',10,10);
- $path=$destinationPath.'/' . $filename;
- $img->save($path);
- $img->resize(300, null, function ($constraint) {
- $constraint->aspectRatio();
- });
- // $img->insert($watermark, 'bottom-right',10,10);
- $img->save($destinationPath . '/tumb/' . $filename);
- $product->image = $filename;
- $product->save();
- }
- else
- {
- return redirect()->back()->with('danger', 'خطا در آپلود فایل.');
- }
- }
- }
- });
- return Redirect::route('dashboard.image-gallery.index')->with('success', 'با موفقیت ثبت شد.');
- }
- else
- {
- return Redirect::back()->withInput()->withErrors($valid->messages());
- }
- } catch (LoginRequiredException $ex) {
- return Redirect::back()->withInput()->with('danger',$e->getMessage());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement