May 16, 2019
0
Level 5
upload pdf file base64
I'm trying to upload a pdf file encoded in base64
the file got uploaded but it's not accessible " PDF document is damaged"
this is my code :
public function handleUploadPdf(Request $request){
$image = $request->input('image'); // your base64 encoded
$image = str_replace('data:application/pdf;base64,', '', $image);
$image = str_replace(' ', '+', $image);
$imageName = str_random(10).'.'.'pdf';
\File::put(public_path(). '/images/' . $imageName, base64_decode($image));
return response()->json(['status'=>200]);
}
what is causing this issue ? thank you in advance
Please or to participate in this conversation.