Web Content Tips - Part 5: If you want to send a file and manually trigger its download mechanism, you can modify the header. We send the browser appropriate Content-Type and Content-Disposition headers. Look this sample:
<?php
$file = "test.txt";
header("Content-Type: plain/text");
header("Content-Length: " . filesize($file));
header("Content-Disposition: attachment; filename=".basename($file));
readfile($file);
?>
Another sample:
<?php
$file = "test.zip";
header("Content-Type: application/octet-stream");
header("Content-Length: " . filesize($file));
header("Content-Disposition: attachment; filename=".basename($file));
readfile($file);
?>
advertisements
blog comments powered by Disqus

