Extract a file from a ZIP string

前端 未结 6 1759
野趣味
野趣味 2020-12-15 17:54

I have a BASE64 string of a zip file that contains one single XML file.

Any ideas on how I could get the contents of the XML file without having to deal with files o

6条回答
  •  庸人自扰
    2020-12-15 18:51

    If you know the file name inside the .zip, just do this:

    If you have a plain string, just do this:

    [edit] Documentation is there: http://www.php.net/manual/en/wrappers.php

    From the comments: if you don't have a base64 encoded string, you need to urlencode() it before using the data:// wrapper.

    [edit 2] Even if you already found a solution with a file, there's a solution (to test) I didn't see in your answer:

    open('data::text/plain,'.urlencode($base64_decoded_string));
    $zip2 = new ZipArchive;
    $zip2->open('data::text/plain;base64,'.urlencode($base64_string));
    

提交回复
热议问题