codeigniter pdf file dwnload link

0
17

html file

$link_url = 'pages/download/credential/'.$val["credential_file"];

<p class=”text-center mt-2″><?php if($val[“credential_file”]!=” && file_exists(UPLOAD_DIR.”/credential/”.$val[“credential_file”])){?><a href=”<?php echo $link_url;?>” title=”Download” class=”dwn-pdf dwnd-butt”>Download PDF</a><?php }else{?><a href=”javascript:void(0);” onclick=”alert(‘credential not available currently.’);” class=”dwnd-butt”>Download PDF</a><?php }?></p>

controller function
public function download($dirname="", $filename=""){
if($filename){
$data=file_get_contents(UPLOAD_DIR.'/'.$dirname.'/'.$filename);
$this->load->helper("download");
force_download($filename,$data);
}else{
redirect("");
}
}