Reputation: 359
I want to encode binary file into base64 and put it into php page (inline with the code), And when request that page it streams the file to the browser,popup a download dialog.
Any ideas
Upvotes: 0
Views: 3133
Reputation: 83
Seems pretty straightforward. As with readfile, use http headers to force download, and then echo the encoded string.
$decoded_data = base64_decode($encoded_data);
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . strlen($decoded_data);
ob_clean();
flush();
echo $decoded_data;
exit;
Upvotes: 1
Reputation: 4147
Perhaps this example can help you http://www.php.net/manual/en/function.base64-encode.php#105200
Regards!
Upvotes: 0