phpeveryday.com

The best tutorial of php, php framework, php strategies, object oriented oriented,


Web Content: Forcing Browser Downloads

Tag: web content, browser, download   Category: PHP Basic
post: 28 Apr 2008 read: 115


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);

?>



| Give Your Opinion | Recommend
Share and Bookmark to: These icons link to social bookmarking sites where readers can share and discover new web pages.
digg del.icio.us technorati Ma.gnolia BlinkList

Recommended articles by other readers:
Web Services: How PHP Kiss VB.NET? (Part 1)
Chart: How to Build Cool Animation Real Time Chart
Joomla: Fast Road to Understand Component Programming
Email: Send Attachement Mail
mod_rewrite - Part 1: create your "fantasy" URL

What do You Think?
Your Name *:
Email *:
(Will not be published)
Website/URL:
Your Comment *:
* Required


615
posting