如何为Base64字符串导出到文件,在服务器端,而不保存在网络服务器,直接被PHP? [英] How to export a Base64 string to a file, on server side, without saving it in web server, directly by 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 FILEID = 23413 的,我所做的:
In my PHP page, http://example.com/save.php?fileid=23413, I did:
- 我可以使用
回声();
打印Base64编码字符串。所以,有一位与我的 MySQL的查询。 没问题 - 我已经删除
回声();
从我的 PHP 页 - 我试图用
base64_de code();
脱code 的Base64 字符串的文件。我想,当我nagivate此页面,则将导出的文件。但是,它返回一个空页。
- I can use
echo();
for printing Base64 strings. So, there is no problem with my MySQL queries. - I have delete
echo();
from my PHP page. - 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屋!