Now, the CSV file is exported in reports folder. Instead i want the browser to ask where to export the file. so that i can export the file in desired location of client machine and avoid storing those files in server (i.e)reports folder.
$this->load->dbutil();
$this->load->helper('file');
$this->load->helper('download');
$selProducts= $this->db->query("SELECT * FROM tablename");
$data= $this->dbutil->csv_from_result($selProducts);
$randomidgenerated = "reports/".date('Y-m-d').".csv";
if(file_exists(FCPATH.$randomidgenerated)){
$randomidgenerated = "reports/".date('Y-m-d')."_".random_string('alnum', 3).".csv";
}
if ( ! write_file($randomidgenerated, $data))
{
echo 'Unable to write the file';
}
$data = file_get_contents($randomidgenerated);
force_download($randomidgenerated, $data, TRUE);