Ejemplo n.º 1
0
 function large_thumbnail($protocol)
 {
     $pbuser = User::where('email', '=', Session::get('pb_user_email'))->first();
     $pbuserid = $pbuser->id;
     $profilepic = Profilepic::where('user_id', '=', $pbuserid)->first();
     $profilepic_count = Profilepic::where('user_id', '=', $pbuserid)->count();
     /*function base_url($protocol){
     			return $protocol."://".$_SERVER['HTTP_HOST']."/";
     		}*/
     $base_url = $protocol . "://" . $_SERVER['HTTP_HOST'] . "/";
     if ($profilepic_count == 0) {
         // echo default image path
         //echo base_url("http")."pb-assets/img/main_logo/profile_pic_default_30.png";
         echo $base_url . "pb-assets/img/main_logo/profile_pic_default.png";
     } else {
         $profilepic_path = $profilepic->profilepic_path;
         $haystack = "";
         $needles = $profilepic_path;
         $profilepic_path = substr_replace($needles, $haystack, 0, 7);
         $profilepic_name = $profilepic->profilepic_name;
         $profilepic_60 = $profilepic->profilepic_60;
         // remove
         // echo base_url("http").$profilepic_path.$profilepic_30.$profilepic_name;
         echo $base_url . $profilepic_path . $profilepic_name;
     }
 }
 public function profilepic()
 {
     // getting all of the post data
     $file = array('image' => Input::file('image'));
     // setting up rules
     $rules = array('image' => 'required|mimes:jpeg,jpg,png|max:20kb');
     //mimes:jpeg,bmp,png and for max size max:10000
     // doing the validation, passing post data, rules and the messages
     $validator = Validator::make($file, $rules);
     if ($validator->fails()) {
         // send back to the page with the input data and errors
         return Redirect::to('dashboard/upload')->with('message', 'No image uploaded or does not support file type.( size: 200px by 200px )');
     } else {
         // checking file is valid.
         if (Input::file('image')->isValid()) {
             // check if profile pic exist @update else: update
             $pbuser = User::where('email', '=', Session::get('pb_user_email'))->first();
             $pbuserid = $pbuser->id;
             $profilepic_count = Profilepic::where('user_id', '=', $pbuserid)->count();
             if ($profilepic_count == 0) {
                 // insert image
                 $destinationPath = 'public/pb-uploads/profile_pic/';
                 // upload path
                 $extension = Input::file('image')->getClientOriginalExtension();
                 // getting image extension
                 $original_name = Input::file('image')->getClientOriginalName();
                 $random_number = rand(11111, 99999);
                 $fileName = $random_number . '.' . $extension;
                 // renaming image
                 Input::file('image')->move($destinationPath, $fileName);
                 // uploading file to given path
                 // sending back with message
                 // resize the file to 30 by 30, 60 by 60, 150 px 150px
                 // 30 by 30
                 $unresized_img = Image::make($destinationPath . $fileName);
                 $unresized_img->resize(30, 30);
                 $destinationPath_30 = 'public/pb-uploads/profile_pic/' . $random_number . '/';
                 File::makeDirectory($destinationPath_30, $mode = 0777, $recursive = false);
                 $unresized_img->save($destinationPath_30 . '30_30_' . $fileName);
                 // 60 by 60
                 $unresized_img = Image::make($destinationPath . $fileName);
                 $unresized_img->resize(60, 60);
                 $destinationPath_30 = 'public/pb-uploads/profile_pic/' . $random_number . '/';
                 $unresized_img->save($destinationPath_30 . '60_60_' . $fileName);
                 // move the large file to the current folder.
                 File::move($destinationPath . $fileName, $destinationPath_30 . $fileName);
                 // save the files to the database.
                 $profilepic = new Profilepic();
                 $pbuser = User::where('email', '=', Session::get('pb_user_email'))->first();
                 $pbuserid = $pbuser->id;
                 $profilepic->user_id = $pbuserid;
                 $profilepic->profilepic_name = $fileName;
                 $profilepic->profilepic_path = $destinationPath_30;
                 $profilepic->profilepic_30 = "30_30_";
                 $profilepic->profilepic_60 = "60_60_";
                 $profilepic->profilepic_extension = $extension;
                 $profilepic->save();
                 Session::flash('welcome_back', 'Upload successfully');
                 return Redirect::to('dashboard/upload');
             } else {
                 // update image
                 // delete the existing folder...
                 $pbuser = User::where('email', '=', Session::get('pb_user_email'))->first();
                 $pbuserid = $pbuser->id;
                 $existing_profilepic = Profilepic::where('user_id', '=', $pbuserid)->first();
                 $existing_profilepic_path = $existing_profilepic->profilepic_path;
                 File::deleteDirectory($existing_profilepic_path, $preserve = false);
                 $destinationPath = 'public/pb-uploads/profile_pic/';
                 // upload path
                 $extension = Input::file('image')->getClientOriginalExtension();
                 // getting image extension
                 $original_name = Input::file('image')->getClientOriginalName();
                 $random_number = rand(11111, 99999);
                 $fileName = $random_number . '.' . $extension;
                 // renaming image
                 Input::file('image')->move($destinationPath, $fileName);
                 // uploading file to given path
                 // sending back with message
                 // resize the file to 30 by 30, 60 by 60, 150 px 150px
                 // 30 by 30
                 $unresized_img = Image::make($destinationPath . $fileName);
                 $unresized_img->resize(30, 30);
                 $destinationPath_30 = 'public/pb-uploads/profile_pic/' . $random_number . '/';
                 File::makeDirectory($destinationPath_30, $mode = 0777, $recursive = false);
                 $unresized_img->save($destinationPath_30 . '30_30_' . $fileName);
                 // 60 by 60
                 $unresized_img = Image::make($destinationPath . $fileName);
                 $unresized_img->resize(60, 60);
                 $destinationPath_30 = 'public/pb-uploads/profile_pic/' . $random_number . '/';
                 $unresized_img->save($destinationPath_30 . '60_60_' . $fileName);
                 // move the large file to the current folder.
                 File::move($destinationPath . $fileName, $destinationPath_30 . $fileName);
                 // save the files to the database.
                 $pbuser = User::where('email', '=', Session::get('pb_user_email'))->first();
                 $pbuserid = $pbuser->id;
                 $profilepic = Profilepic::where('user_id', '=', $pbuserid)->first();
                 $profilepic->user_id = $pbuserid;
                 $profilepic->profilepic_name = $fileName;
                 $profilepic->profilepic_path = $destinationPath_30;
                 $profilepic->profilepic_30 = "30_30_";
                 $profilepic->profilepic_60 = "60_60_";
                 $profilepic->profilepic_extension = $extension;
                 $profilepic->save();
                 Session::flash('welcome_back', 'Upload successfully | Updated');
                 return Redirect::to('dashboard/upload');
             }
         } else {
             // sending back with error message.
             Session::flash('message', 'uploaded file is not valid');
             return Redirect::to('dashboard/upload');
         }
     }
 }