I am trying to create link to save browser output as file without creating file on server.
This is what I got so far:
<?php
ob_start();
?>
<html>
webpage content
</html>
<?php
$page = ob_get_contents();
ob_end_flush();
$file= time().'.html';
file_put_contents($file, $page);
ob_start();
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.basename($file).'"');
header('Content-Length: ' . filesize($file));
ob_end_flush();
?>
<a href="<?php echo $file; ?>.php">Download output as file</a>
How can i create such link WITHOUT SAVING file on server?
Thank you for your suggestions/ideas/code.