duanou3868 2015-06-02 01:02
浏览 110

如何将Base64字符串导出到服务器端的文件,而不是直接通过PHP将其保存在Web服务器中?

I am using PHP and MySQL for my programming.


I have stored some Base64 strings (which are encoded from files). I know that base64_decode(); can decode Base64 strings to files.

Now, I want to decode these Base64 strings to files, by PHP, without saving it in my web server; but, web browser can download it from web link (http://example.com/save.php?fileid=23413).

In my PHP page, http://example.com/save.php?fileid=23413, I did:

  1. I can use echo(); for printing Base64 strings. So, there is no problem with my MySQL queries.
  2. I have delete echo(); from my PHP page.
  3. I tried to use base64_decode(); to decode Base64 strings to files. I want when I nagivate to this page, it will export a file. But, It returns an empty page.

Can you help me to decode Base64 strings to files, by PHP, without saving it in my web server, and web browser can download it from web link (http://example.com/save.php?fileid=23413)?

  • 写回答

1条回答 默认 最新

  • drxzpo70788179614 2015-06-02 01:20
    关注

    Try adding headers to the script before echoing the output

    header('Content-Description: File Transfer');
    header("Content-type: application/octet-stream");
    header("Content-disposition: attachment; filename= ".$file."");
    echo base64_decode($file);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计