dongxiaoke2018 2019-06-23 12:25
浏览 105
已采纳

php如何从二进制数据中显示文件

I have function that run web-service and bring me binary file:

$params->xmlRequest = $paramsStr;

$result = $s->__call("SubmitXmlString",array($params));

$obj_pros = get_object_vars($result);
$xml =  $obj_pros['SubmitXmlStringResult']; 
$xml = simplexml_load_string($xml); 

return ($xml);  

example for response:

<PnrGetReportDoc ReportName="ExternalDocument">
    <Report ID="6214" Type="pdf" Name="file name" IsCompressed="1">
        <![CDATA[JVBERi0xLjcNCiW1tbW1DQoxIDAgb2JqDQo8PC9UeXBlL0NhdGFsb2cvUGFnZXMgMiAQolJU......................VPRg==]]>
        </Report>
    <ReportImages>
</ReportImages>
</PnrGetReportDoc>

I would like to ECHO the content in order to display the file

I tried to echo the binary but: 1. PDF isn't display

  1. binary characters start without the opening notes: <![CDATA[

This is my php file where i'm trying to display the file:

header('Content-type: application/'pdf);
$fileData = get_file_data ($_GET['fileID']);

echo $fileData->Report;
  • 写回答

1条回答 默认 最新

  • dongshi4589 2019-06-23 13:57
    关注

    That is not binary. Precisely, XML is well known for being a plain text data format.

    From the sample data you've shared I imagine it's Base64, a popular algorithm to encode binary data as plain text. PHP has a native function to decode it.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮