I am trying to download a remote pdf
file in codeigniter which is password protected. Actually i have the username and password for the file, but i need to download the file directly without prompting by asking username and password for viewing it.I was trying with the below code in controller, but i am not sure that i tried correctly or not.
Actually, downloading is happening, but after opening the file its showing 'Failed to load PDF document'.
One more thing, i dont have a pre idea about the filename of the file to be downloaded, one file should be there corresponding to a cart id. So i am not sure whether the line header("Content-disposition: attachment; filename=tickets.pdf");
i used in below code is correct or not. I supposed it must be our custom file name for the file to be downloaded.
Below is the code in controller.
function file_download(){
$cart_id = $this->uri->segment(3);//Getting cart id from the url
$ticket_url=Base_url.'carts/'.$cart_id.'/tickets';
header('Content-Type: application/octet-stream');
header("Content-Transfer-Encoding: Binary");
header("Content-disposition: attachment; filename=tickets.pdf");
ob_clean(); flush();
readfile($ticket_url);
exit();
}
Thanks in advance!