0

I am posting a base64 image with ajax to PHP...But I wanna check specs before move to image to folder...

  1. how to check if image is base64 image or not...
  2. 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);}

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.