mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange.git
synced 2026-08-19 04:14:04 +00:00
fix/uploadPictureInCompressedMethod
This commit is contained in:
@@ -576,7 +576,7 @@ class BookingController extends Controller
|
||||
return response()->json(['book_id'=>$book_id],200);
|
||||
}
|
||||
|
||||
public function uploadbankslip(Request $request, $id)
|
||||
private function uploadbankslip(Request $request, $id)
|
||||
{
|
||||
$booking = Booking::where('user_id',Auth::user()->id)->where('id',$id)->first();
|
||||
|
||||
@@ -586,40 +586,48 @@ class BookingController extends Controller
|
||||
return response()->json(['message'=>'Access denied'], 403);
|
||||
}
|
||||
|
||||
$validator = Validator::make($request->all(), [
|
||||
'file' => 'mimes:jpg,jpeg,bmp,png,xls,xlsx,doc,docx,pdf'
|
||||
]);
|
||||
// $validator = Validator::make($request->all(), [
|
||||
// 'slip_image' => 'mimes:jpg,jpeg,bmp,png,xls,xlsx,doc,docx,pdf'
|
||||
// ]);
|
||||
|
||||
if($validator->fails())
|
||||
{
|
||||
return response()->json(['message'=>'Incorrect format'],400);
|
||||
}
|
||||
// if($validator->fails())
|
||||
// {
|
||||
// return response()->json(['message'=>'Incorrect format'],400);
|
||||
// }
|
||||
|
||||
$validator = Validator::make($request->all(), [
|
||||
'file' => 'max:10000' // image size
|
||||
]);
|
||||
// $validator = Validator::make($request->all(), [
|
||||
// 'slip_image' => 'max:10000' // image size
|
||||
// ]);
|
||||
|
||||
if($validator->fails())
|
||||
{
|
||||
return response()->json(['message'=>'Image too large, upload files up to 3 MB'], 400);
|
||||
}
|
||||
// if($validator->fails())
|
||||
// {
|
||||
// return response()->json(['message'=>'Image too large, upload files up to 3 MB'], 400);
|
||||
// }
|
||||
|
||||
|
||||
if($bankslip_file = $request->file('file'))
|
||||
if($bankslip_file = $request->input('slip_image'))
|
||||
|
||||
{
|
||||
/* End Validation */
|
||||
$filename = $bankslip_file->getClientOriginalName();
|
||||
$ext = $bankslip_file->getClientOriginalExtension();
|
||||
|
||||
|
||||
$unique_name = 'bank_slip_' . md5($filename. time()); // probably not a good idea
|
||||
$unique_image_path = $unique_name. '.' .$ext;
|
||||
|
||||
$upload_path = Storage::disk('public')->putFileAs(
|
||||
'user_bankslip', $bankslip_file, $unique_image_path
|
||||
);
|
||||
$ext = explode('/', explode(':', substr($bankslip_file, 0, strpos($bankslip_file, ';')))[1])[1];
|
||||
$img = str_replace('data:image/'.$ext.';base64,', '', $bankslip_file);
|
||||
$img = str_replace(' ', '+', $img);
|
||||
$data = base64_decode($img);
|
||||
$file_name = 'bank_slip_' . md5(time()).'.'.$ext;
|
||||
if($bankslip_file!=""){
|
||||
// storing image in storage/app/public Folder
|
||||
$upload_path = \Storage::disk('public')->put('user_bankslip'.'/'.$file_name, $data);
|
||||
}
|
||||
// /* End Validation */
|
||||
// // $filename = $bankslip_file->getClientOriginalName();
|
||||
//
|
||||
|
||||
// $unique_name = 'bank_slip_' . md5(time()); // probably not a good idea
|
||||
// $unique_image_path = $unique_name. '.' .'jpg';
|
||||
// $image_parts = explode(";base64,", $bankslip_file);
|
||||
// $upload_path = \Storage::disk('public')->put('user_bankslip'.'/'.$unique_image_path,base64_decode(base64_decode($image_parts[1])));
|
||||
// // $upload_path = Storage::disk('public')->putFileAs(
|
||||
// // 'user_bankslip', base64_decode($image), $unique_image_path
|
||||
// // );
|
||||
if($upload_path){
|
||||
$user_bankslip = $booking->userBankSlip()->first();
|
||||
|
||||
@@ -628,8 +636,8 @@ class BookingController extends Controller
|
||||
$user_bankslip = new UserBankSlip;
|
||||
}
|
||||
$user_bankslip->booking_id = $booking->id;
|
||||
$user_bankslip->bankslip_path = $upload_path;
|
||||
$user_bankslip->transfer_amount = $request->input('transfer_amount');
|
||||
$user_bankslip->bankslip_path = 'user_bankslip'.'/'.$file_name;
|
||||
$user_bankslip->transfer_amount = null;
|
||||
$user_bankslip->save();
|
||||
|
||||
|
||||
@@ -647,6 +655,7 @@ class BookingController extends Controller
|
||||
}
|
||||
|
||||
public function updateBankSlipAmount(Request $request, $id){
|
||||
$this->uploadbankslip($request, $id);
|
||||
$booking = Booking::where('user_id',Auth::user()->id)->where('id',$id)->first();
|
||||
$user_bankslip = $booking->userBankSlip()->first();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user