When I pass a value of javascript pro php it modifies

Asked

Viewed 17 times

-1

I have an image converted to Base64 ,when I send this string from javascript pro php it modifies this string.inserir a descrição da imagem aqui

1 answer

1

Hi, Adolfo!

How are you doing this JS conversion? Something like this? This below shows in the console 3 results for the text "Hello World!": original, Base64 and Decoded.

   const str = "Olá mundo!";
   const base64 = btoa(str);
   const decode = atob(base64);
   console.log("Original: " + str);
   console.log("Base64: " + base64);
   console.log("Decodificada: " + decode);
<!doctype html>
<html lang="pt_br">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <title>Olá mundo!</title>
  </head>
    
  <body>
    <h1>Olá mundo!</h1>
      
   
  </body>
</html>

If you send this Base64 to PHP the result changes? Kind of:

<?php
   $str = 'tua base64 string aqui';
   echo base64_decode(urldecode($str));
?>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.