I am trying to export few data in CSV file. Though the file is successfully downloaded as well as stored in particular path. If I opened downloaded file from the browser, file showing empty results I don't know where I made mistake please help me out
My Controller
public function export_webdata($p_id,$inptid){
$project = $this->Lead_Model->get_project_single($p_id);
$filename = $project[0]->p_name.'_WebsiteInfo_'.time().'.csv';
$path = getcwd().'/public/files/'.$project[0]->p_name.'/';
if (!file_exists($path)){
mkdir($path, 0777, true);
}
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename="'.$filename.'";');
$output = fopen($path.$filename, 'w');
$header = array("Company","Country","Website");
fputcsv($output, $header);
$extdata = $this->Lead_Model->webdata_export($inptid);
foreach ($extdata as $key=>$line){
fputcsv($output,$line);
}
fclose($output);
}
My Model
public function webdata_export($inptid)
{
$response = array();
$db5 = $this->load->database('output_db', TRUE);
$q = $db5->select('Company,Country,Website')->get_where('website_info', ['input_id' => $inptid, 'type_id' => 2,'uploaded_by' => $this->session->admin_id]);
$response = $q->result_array();
return $response;
}