Beispiel #1
0
 public function uploadidcard()
 {
     $root_url = dirname($_SERVER['PHP_SELF']);
     if (Request::exists('btn-upload')) {
         $user_id = Request::input('user_id');
         $file = Request::file('uploader');
         $path = 'upload_file/idcard/default';
         $filename = $file->getClientOriginalName();
         //check file extension
         $ext = pathinfo($filename, PATHINFO_EXTENSION);
         $newfilename = "idcard_id" . $user_id . "." . $ext;
         $file->move($path, $newfilename);
         if ($ext == 'pdf') {
             //if pdf set pdf icon to thumbnail
             $thunbnail = 'upload_file/idcard/thumbnail/pdf.png';
         } else {
             if ($ext == 'jpg' || $ext == 'png' || $ext == 'gif') {
                 //if image create thumbnail
                 $img = Image::make('upload_file/idcard/default/' . $newfilename);
                 if ($img->height() == $img->width()) {
                     $imgresult = $img->resize(206, 206);
                 } else {
                     if ($img->height() > $img->width()) {
                         $imgresult = $img->resize(206, null, function ($constraint) {
                             $constraint->aspectRatio();
                         });
                     } else {
                         $imgresult = $img->resize(null, 206, function ($constraint) {
                             $constraint->aspectRatio();
                         });
                     }
                 }
                 //set and save resize image to thumbnail
                 $imgresult->save('upload_file/idcard/thumbnail/' . $newfilename);
                 $thunbnail = 'upload_file/idcard/thumbnail/' . $newfilename;
             }
         }
         $count = idcard::where('id_user', '=', $user_id)->count();
         if ($count == 1) {
             $dbidcard = idcard::where('id_user', '=', $user_id)->first();
             $oldext = pathinfo($dbidcard->id_name, PATHINFO_EXTENSION);
             $image_path = '../' . $root_url . '/upload_file/idcard/default/' . $dbidcard->id_name;
             if ($oldext != 'pdf') {
                 $image_thumbnail = '..' . $root_url . '/' . $dbidcard->id_thumbnail;
                 if ($newfilename != $dbidcard->id_name) {
                     unlink($image_thumbnail);
                 }
             }
             if ($newfilename != $dbidcard->id_name) {
                 unlink($image_path);
             }
             //update link
             $dbidcard->id_name = $newfilename;
             $dbidcard->id_thumbnail = $thunbnail;
             $dbidcard->save();
             //update id validate status
             $user = Member::where('id', '=', $user_id)->first();
             $validate = $user->validate;
             $mail_st = substr($validate, 1, 1);
             $verify_id = substr($validate, 3, 1);
             $new_validate = "1" . $mail_st . "1" . $verify_id;
             $user->validate = $new_validate;
             $user->save();
             //End update id validate status
         } else {
             //save to batabase
             $dbidcard = new idcard();
             $dbidcard->id_name = $newfilename;
             $dbidcard->id_user = $user_id;
             $dbidcard->id_thumbnail = $thunbnail;
             $dbidcard->save();
             //update id validate status
             $user = Member::where('id', '=', $user_id)->first();
             $validate = $user->validate;
             $mail_st = substr($validate, 1, 1);
             $verify_id = substr($validate, 3, 1);
             $new_validate = "1" . $mail_st . "1" . $verify_id;
             $user->validate = $new_validate;
             $user->save();
             //End update id validate status
         }
     }
     return redirect()->back();
 }
Beispiel #2
0
 public static function save_database($user_id, $save_name, $role_method)
 {
     if ($role_method == "profile") {
         $count = imageDB::where('image_user', '=', $user_id)->count();
         if ($count == 1) {
             $database = imageDB::where('image_user', '=', $user_id)->first();
         } else {
             $database = new imageDB();
         }
         $database->image_name = $save_name;
         $database->image_thumbnail = "upload_file/images/thumbnail/" . $save_name;
         $database->image_user = $user_id;
     } else {
         $count = idcardDB::where('id_user', '=', $user_id)->count();
         if ($count == 1) {
             $database = idcardDB::where('id_user', '=', $user_id)->first();
         } else {
             $database = new idcardDB();
         }
         $database->id_name = $save_name;
         $database->id_thumbnail = "upload_file/idcard/thumbnail/" . $save_name;
         $database->id_user = $user_id;
         //update id validate status
         $user = Member::where('id', '=', $user_id)->first();
         $validate = $user->validate;
         $mail_st = substr($validate, 1, 1);
         $verify_id = substr($validate, 3, 1);
         $new_validate = "1" . $mail_st . "1" . $verify_id;
         $user->validate = $new_validate;
         $user->save();
         //End update id validate status
     }
     $database->save();
 }