file download script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
manojsemwal1
Forum Contributor
Posts: 217
Joined: Mon Jun 29, 2009 4:13 am
Location: India

file download script

Post by manojsemwal1 »

anybody having file download script in php or tutorial i used <a href="http://path/to/script/download.php?f=ph ... .zip">Cool PHP Tutorial</a> script it works but after download file file has been currepted.............
mellowman
Forum Commoner
Posts: 62
Joined: Sat Nov 22, 2008 5:37 pm

Re: file download script

Post by mellowman »

Can u explain? What you mean by a file download script...like what exactly do you want it to do.?
pbs
Forum Contributor
Posts: 230
Joined: Fri Nov 07, 2008 5:31 am
Location: Nashik, India
Contact:

Re: file download script

Post by pbs »

You can use this function

Code: Select all

 
function force_download($file)
{
    $dir = "";
    if ((isset($file))&&(file_exists($dir.$file))) 
    {
       header("Content-type: application/force-download");
       header('Content-Disposition: inline; filename="' . $dir.$file . '"');
       header("Content-Transfer-Encoding: Binary");
       header("Content-length: ".filesize($dir.$file));
       header('Content-Type: application/octet-stream');
       header('Content-Disposition: attachment; filename="' . $file . '"');
       readfile("$dir$file");
    }
}
 
 
manojsemwal1
Forum Contributor
Posts: 217
Joined: Mon Jun 29, 2009 4:13 am
Location: India

Re: file download script

Post by manojsemwal1 »

download script means....
i have a site where i want to give a link, through that link the visitor can download the any type of file like doc,zip,pdf etc.
when the visitor click on the link it will ask for save as.

regards,
manojsemwal1
Forum Contributor
Posts: 217
Joined: Mon Jun 29, 2009 4:13 am
Location: India

Re: file download script

Post by manojsemwal1 »

The Above function where i have to define the directory path where we kept the file.....
pbs
Forum Contributor
Posts: 230
Joined: Fri Nov 07, 2008 5:31 am
Location: Nashik, India
Contact:

Re: file download script

Post by pbs »

Yes
manojsemwal1
Forum Contributor
Posts: 217
Joined: Mon Jun 29, 2009 4:13 am
Location: India

Re: file download script

Post by manojsemwal1 »

Dear Friend

iam asking where i have to define folder path...............?
pbs
Forum Contributor
Posts: 230
Joined: Fri Nov 07, 2008 5:31 am
Location: Nashik, India
Contact:

Re: file download script

Post by pbs »

In function there is $dir variable.
Post Reply