Reputation: 315
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:
echo();
for printing Base64 strings. So, there is no problem with my MySQL queries.echo();
from my PHP page.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)?
Upvotes: 2
Views: 2281
Reputation: 1410
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);
Upvotes: 3