I am posting a base64 image with ajax to PHP...But I wanna check specs before move to image to folder...
- how to check if image is base64 image or not...
- how to check if image is larger than 1Mbyte...
or anything else to secure upload... Here is my php upload code:
$img_teknik_1 = $_POST["base64image_1"];
$img_teknik_1 = str_replace('data:image/png;base64,', '', $img_teknik_1);
$img_teknik_1 = str_replace(' ', ' ', $img_teknik_1);
$data_teknik_1 = base64_decode($img_teknik_1);
$file_teknik_1 = UPLOAD_DIR . $resim_kodu . '_teknik_1.png';
$success_1 = file_put_contents($file_teknik_1, $data_teknik_1);}
CodePudding user response:
You can simply use:
strlen($_POST["base64image_1"]) <= 1048576
to check the size of the image (1 KiB = 1024 Bytes)
base64_decode($_POST["base64image_1"]) !== false;
to check the encoding.