Fource to download a file in php as well as in joomla 2.5

I am wondering how to download forcefully a file using php
I am using this code. If any one has more better code please share with us

           $filename = $path . DS . $this->item->file;die();
            if (is_file($path . DS . $this->item->file))
                if (file_exists($filename))
                    header('Content-Description: File Transfer');
                    header('Content-Type: application/octet-stream');
                    header('Content-Disposition: attachment; filename=' . basename($filename));
                    header('Content-Transfer-Encoding: binary');
                    header('Expires: 0');
                    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
                    header('Pragma: public');
                    header('Content-Length: ' . filesize($filename));

Here file path will be like as D:\xampp\htdocs\jm-dmrd\file\noticeboard\pdf\New_Microsoft_Word_Document-.docx



Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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

%d bloggers like this: