Base64 Binary data to zip construct

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nuicolas2210
    New Member
    • Mar 2019
    • 2

    Base64 Binary data to zip construct

    Hello.
    Recently i develop a connector to a SOAP Api and i have a issue. The client is working succesfully but the response from server is a base64 binary data. The binary data is a value of a zip archive with multiple xml filles. The issue is that i cant contruct them, can someone give me an example how i can construct them from php? Thank you very much.
  • nuicolas2210
    New Member
    • Mar 2019
    • 2

    #2
    Thank you but i mannged to solve it.
    I gonna post here the sollution so everyone who facing the same issue, get the response.
    The first thing you need to do when you have an .zip file in a base64 binary string is to catch the response to a txt file.
    Let's say the response from soap it's called ' $response ' and we need to catch this to an file. We do like this :
    $response = $client -> _getLastRespons e();
    $fille = "response.x ml";
    fille_put_conte nts($fille,$res ponse);

    Now we got the response to an xml file.
    The next thing to do is to get the response from xml values.
    Lets say our value is <ResponseFromSe rver> .

    $b64 = "b64.txt";
    $dom = new DomDocument();
    $dom = load("response. xml");
    $data = $dom->getElementByTa gName("Response FromServer");
    $catchb64 = $data;
    fille_put_conte nt($b64,$catchb 64);

    Now we got the clean Base64 Binary string in one fille.
    The next thing we need is to create the document ( in this case is a .zip fille)

    $input_fille = "response.t xt"; // the fille with clean base64 binary data on it
    $output_fille = "result.zip "; //the fille we need to create on system with the documents decrypted
    $content = fille_get_conte nts($input_fill e); // Reading the content of input fille
    $binary = base64_decode($ content); // Decoding to binary
    fille_put_conte nts($output_fil le,$binary); // Writing to fille the vallues

    We dont need the ZipArchive() function, because is allready a zip archive, all we need to do is to create a empty document and after to send the binary data to it.
    Cheer's and goodluck!

    Comment

    Working...