how to open pdf file to another tab in browser using codeigniter
codeigniter
Solution
try this one with a static url. no need any extra words for that.
<a href="<?=base_url('any_folder_name/any_file.pdf')?>" target="_blank">Show My Pdf</a>
New Update
if its work for you then fetch pdf name from database and put the name in the view like
<a href="<?=base_url('index.php/admin/viewMinutesFile/'.$info['doc_id'])?>" target="_blank">Show My Pdf</a>
now in the controller
$this->load->helper('download');
if($this->uri->segment(3))
{
$data = file_get_contents('./file_path/'.$this->uri->segment(3));
}
$name = $this->uri->segment(3);
force_download($name, $data);
Problem
``` im making currently making my thesis about a record management of our university secretary.. in which all papers inside the office will be scanned and uploaded in the system.. i am using codeigniter..one of the feature in my system is to view the pdf file in other window of the browser. but my problem is, when i click the title. only blank page will be displayed in the other tab.. can you help me solve this one?? here is my code controller: function viewMinutesFile(){ if(isset($_GET['id'])){ $id = $_GET['id']; $file = $this->minutes_model->getFile($id); $fp= fopen($file->path, "r"); header("Cache-Control: maxage=1"); header("Pragma: public"); header("Content-type: application/pdf"); header("Content-Disposition: inline; filename=".$file->filename.""); header("Content-Description: PHP Generated Data"); header("Content-Transfer-Encoding: binary"); header('Content-Length:' .filesize($file->path)); ob_clean(); flush(); while (!feof($fp)){ $buff = fread($fp,1024); print $buff; } exit; } } ``` code to open the file: this is my syntax to be clicked by the user so that pdf file will be open in the new tab File index.php/admin/viewMinutesFile? id=" target="_tab">