Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // upload multiple images
- public function uploadImages($vendor_id){
- return View::make('adminpages/uploadImages', array('vendor_id'=>$vendor_id));
- }
- // imgupload for real weddings
- public function imageUpload(){
- //store all the inputs in a variable
- $input = Input::all();
- //define the image rules
- $rules = array(
- 'file' => 'image|max:50000',
- );
- //pass input and rules to validation class
- $validation = Validator::make($input, $rules);
- //if validation fails return json response as error
- if ($validation->fails()) {
- return Response::json('Invalid images', 400);
- }
- //store file input in a varaible
- $file = Input::file('file');
- //get extension of file
- $extension =$file->getClientOriginalExtension();
- $directory = '/uploads/images/';
- //change filename to a random sha1 plus current time
- $filename = "vendor_" . substr(sha1(rand(0,5).time()), 0, 15) . rand(0,100000) .".{$extension}";
- //Move the uploaded file to temp directory
- // $upload_success = $file->move($directory, $filename);
- $s3 = AWS::get('s3');
- $upload_success = $s3->putObject([
- 'ACL' => 'public-read',
- 'Bucket' => 'glam360',
- 'Key' => $directory.$filename,
- 'Body' => fopen($file->getPathname(), 'r'),
- 'ContentType' => 'image/'. $extension
- ]);
- $s3 = \AWS::get('s3');
- // $upload_success = $s3->putObject([
- // 'ACL' => 'public-read',
- // 'Bucket' => 'wedimages',
- // 'Key' => $directory . $filename,
- // 'Body' => fopen($file->getPathname(), 'r'),
- // 'ContentType' => 'image/'. $extension,
- // ]);
- // resize and image and overrite it in its current location
- // $img = Image::make('images/'.$filename)->resize(500,500)->save();
- // $img = Image::make('images/'.$filename);
- //if upload is success
- if( $upload_success )
- {
- //if imageArray session exists
- if (Session::has('tempImages2'))
- {
- //get images array from session
- $imagesArray = Session::get('tempImages2');
- }
- //else create a new imagesArray and store it in session
- else
- {
- $imagesArray= array();
- Session::put('tempImages2', $imagesArray);
- }
- //get imagesArray from session
- $imagesArray = Session::get('tempImages2');
- //push the new image name into imageArray
- array_push($imagesArray, $filename);
- //Override the the current session with thye array which has new image
- Session::put('tempImages2', $imagesArray);
- return Response::json(array('success' => 1, 'data' => $filename), 200);
- }
- //if upload is not success
- else
- {
- //return json response as error
- return Response::json('error');
- }
- }
- public function uploadImagesPost(){
- $input = Input::all();
- //Check if images are set or not
- if( !(Session::has('tempImages2')) OR !(count(Session::get('tempImages2')) > 0) ){
- $input['no_images']="Please upload a few images.";
- return Redirect::back()->withInput($input);
- }
- $tempImages= Session::get('tempImages2');
- $single_arr = json_encode($tempImages);
- $session_data = Session::get('admin_logged_in');
- Session::forget('tempImages2');
- foreach ($tempImages as $value) {
- // $data = DB::table('vendor_images')
- // ->insertGetId(array(
- // 'vendor_id' => $input['vendor_id'],
- // 'image' => $value,
- // 'updated_at' => new DateTime,
- // 'created_at' => new DateTime
- // ));
- $data[] = array('vendor_id' => $input['vendor_id'],
- 'image' => $value,
- 'updated_at' => new DateTime,
- 'created_at' => new DateTime
- );
- }
- $vendor_images_id = DB::table('vendor_images')->insert($data);
- $input['successMsg'] = 'Added successfully!';
- return Redirect::route('admin.dashboard')->withInput($input);
- }
Add Comment
Please, Sign In to add comment