Category Archives: Joomla 2.5

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));
                    ob_clean();
                    flush();
                    readfile($filename);
                    exit;
                }
            }

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

Thanks