Download in PHP

file_download.php:

<?php

$cmd = $_REQUEST['cmd'];

switch($cmd)
{
case ‘download’:  header(“Content-type:application/pdf”);
header(“Content-Disposition:attachment;filename=downloaded.pdf”);

// Put the source in the root directory.if you don’t then change the path accordingly.
readfile(“php5_power_programming.pdf”);
break;

default         : break;
}
?>

Client side:

Simply call the above  script according to the following way:

<a href=”/file_download.php?cmd=’download’ “>download</a> or the you can do it with a little bit help of javascript.

that’s enough.Very simple.Isn’t it?

Advertisement

~ by Kal Purush on October 20, 2009.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.