Extract a file from a ZIP string

前端 未结 6 1764
野趣味
野趣味 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:34

    toster-cx had it right,you should award him the points, this is an example where the zip comes from a soap response as a byte array (binary), the content is an XML file:

    $objResponse = $objClient->__soapCall("sendBill",array(parameters));
    $fileData=unzipByteArray($objResponse->applicationResponse);
    header("Content-type: text/xml");
    echo $fileData;
    function unzipByteArray($data){
      /*this firts is a directory*/
      $head = unpack("Vsig/vver/vflag/vmeth/vmodt/vmodd/Vcrc/Vcsize/Vsize/vnamelen/vexlen", substr($data,0,30));
      $filename = substr($data,30,$head['namelen']);
      $if=30+$head['namelen']+$head['exlen']+$head['csize'];
     /*this second is the actua file*/
      $head = unpack("Vsig/vver/vflag/vmeth/vmodt/vmodd/Vcrc/Vcsize/Vsize/vnamelen/vexlen", substr($data,$if,30));
      $raw = gzinflate(substr($data,$if+$head['namelen']+$head['exlen']+30,$head['csize']));
      /*you can create a loop and continue decompressing more files if the were*/
      return $raw;
    }
    

提交回复
热议问题