如何为Base64字符串导出到文件,在服务器端,而不保存在网络服务器,直接被PHP? [英] How to export a Base64 string to a file, on server side, without saving it in web server, directly by PHP?

查看:207
本文介绍了如何为Base64字符串导出到文件,在服务器端,而不保存在网络服务器,直接被PHP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的 PHP 的MySQL 作为我的节目。

I am using PHP and MySQL for my programming.

我已经存储了一些的Base64 字符串(这是途中从文件codeD)。我知道, base64_de code(); 可以去code 的Base64 字符串文件

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

现在,我要脱code这些的Base64 字符串文件,由 PHP ,而不保存在我的 Web服务器 ;但是, Web浏览器下载网络链接(适用的 http://example.com/save.php?fileid=23413 )。

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).

在我的 PHP 页, http://example.com/ ?save.php FIL​​EID = 23413 的,我所做的:

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


  1. 我可以使用回声(); 打印Base64编码字符串。所以,有一位与我的 MySQL的查询。
  2. 没问题
  3. 我已经删除回声(); 从我的 PHP

  4. 我试图用 base64_de code(); 脱code 的Base64 字符串的文件。我想,当我nagivate此页面,则将导出的文件。但是,它返回一个页。

  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.

您可以帮我去code 的Base64 字符串文件,由 PHP ,而不保存在我的 Web服务器 Web浏览器下载网络链接(适用的 http://example.com/save.php?fileid=23413 )?


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)?

推荐答案

尝试呼应输出之前添加标头脚本

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);

这篇关于如何为Base64字符串导出到文件,在服务器端,而不保存在网络服务器,直接被PHP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆