PHP: Base64 decode help

I am integrating with Http integration through the app-server

However, I can not for the life of me work out how to decode the base64 to a readable format before the data hits the destination.

Here is my php code at end point

<?php header("Content-type: application/json"); $json = file_get_contents("php://input"); $obj = json_decode($json); $decoded = base64_decode(json_encode($obj->data)); $fp = @fopen("data.txt", "a"); fwrite($fp,$decoded); fwrite($fp,"\r\n"); fclose($fp); ?>

It is the part between the app-server and the json I am missing to decode.I wish that when the data is forwarded to the http end point that it automatically displays in readable format, each time data is pushed up.
I have lookd on this forum and search engines, but no luck.

Can anyone provide a step by step on this?

Did you receive anything in “data.txt”. If not you should edit your url on lora-app-server.
Your code is correct.

I do recieve data, but it is not decoded when send to tmp.txt file, when send to data.txt file it comes up in hex no decoded

Did you try to decode by terminal on linux? Try it to know it’s incorrect or correct

The command is : base64 -d <<< this is your encode data | hexdump -C

Base64 decoded will most likely be hex if what was encoded was Hex bytes.

Can you confirm if the original data received is the same as the output in data.txt?
Base64 encoding will give you an ASCII output which will be a few characters longer than the original input.

@Anh_Quan_Tong’s suggestion above should help

Yes it was hex, I ended up HTTP to my PC, and doing it in C# on there.

The data that went into data.txt was different to tmp.txt. In data it was pure hex. I don’t use those now, as in previous post explained what I ended up doing.