Exemplo n.º 1
0
 /**
  * deletes a hall
  *
  * @param Request $request
  */
 public function admin_delete_hall(Request $request)
 {
     $hall = Hall::find($request->input('id'));
     $hall->delete();
 }
 public function uploadImage(\Illuminate\Http\Request $request)
 {
     if (Request::ajax()) {
         //  echo $request['file'];
         /*	  
         $target_path = "C:/wamp/www/BookMyPartyVenue/public/images/halls/";
         
         //echo $_FILES['file']['name'];
         $target_path = $target_path . basename( $_FILES['file']['name']); 
         
         if(move_uploaded_file($_FILES['file']['tmp_name'], $target_path)) {
           //  echo "The file ".  basename( $_FILES['file']['name']). 
             " has been uploaded";
         } else{
            // echo "There was an error uploading the file, please try again!";
         }
         echo url("/images/halls/".basename( $_FILES['file']['name']));
         */
         $fileName = $_FILES["file"]["name"];
         $kaboom = explode(".", $fileName);
         $ext = end($kaboom);
         $target_path = 'images/halls/hall_' . $request->id . '_' . $request->type . '.' . $ext;
         if (move_uploaded_file($_FILES['file']['tmp_name'], $target_path)) {
             //  echo "The file ".  basename( $_FILES['file']['name']).
             " has been uploaded";
         } else {
             //  echo "There was an error uploading the file, please try again!";
         }
         Hall::where('id', $request->id)->update([$request->type => 'hall_' . $request->id . '_' . $request->type . '.' . $ext]);
         $resized_file = 'images/halls/hall_' . $request->id . '_' . $request->type . '.' . $ext;
         if ($request->type == 'avatar') {
             $w = 250;
             $h = 250;
         } else {
             if ($request->type == 'cover') {
                 $w = 1200;
                 $h = 400;
             } else {
                 if ($request->type == 'platinum_cover') {
                     $w = 600;
                     $h = 200;
                 } else {
                     if ($request->type == 'gold_cover') {
                         $w = 150;
                         $h = 200;
                     } else {
                         if ($request->type == 'silver_cover') {
                             $w = 150;
                             $h = 100;
                         } else {
                             if ($request->type == 'banner') {
                                 $w = 300;
                                 $h = 100;
                             }
                         }
                     }
                 }
             }
         }
         list($w_orig, $h_orig) = getimagesize($target_path);
         /*  $scale_ratio = $w_orig / $h_orig;
             if (($w / $h) > $scale_ratio) {
                    $w = $h * $scale_ratio;
             } else {
                    $h = $w / $scale_ratio;
             } */
         $img = "";
         $ext = strtolower($ext);
         if ($ext == "gif") {
             $img = imagecreatefromgif($target_path);
         } else {
             if ($ext == "png") {
                 $img = imagecreatefrompng($target_path);
             } else {
                 $img = imagecreatefromjpeg($target_path);
             }
         }
         $tci = imagecreatetruecolor($w, $h);
         // imagecopyresampled(dst_img, src_img, dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h)
         imagecopyresampled($tci, $img, 0, 0, 0, 0, $w, $h, $w_orig, $h_orig);
         imagejpeg($tci, $resized_file, 80);
         echo url('/images/halls/hall_' . $request->id . '_' . $request->type . '.' . $ext);
     }
 }