I'm using codeigniter to create a CSV file, and I can write successfully inside the application structure, but not outside. The reason why I want to create the file outside the application structure cause I get a 403 permissions error when linking to the file.
Either my folder permissions are wrong (I've used 777) or my code is wrong. Please help.
CodeIgniter
$this->load->dbutil();
$this->load->helper('file');
$delimiter = ",";
$newline = "
";
$query = $this->db->query("SELECT * FROM songlist");
$data = $this->dbutil->csv_from_result($query, $delimiter, $newline);
$filePath = '_/files/songlist.csv';
echo "filePath=". $filePath. "</br>";
if (! write_file($filePath, $data)){
echo 'not done';
} else {
echo anchor(base_url(). $filePath);
}
}
I think the problem is that "_" is not a valid folder for web. Try changing it.
If you want to create the file in "mysite/downloads" you filepath would be:
$filePath = '../downloads/songlist.csv';
And i see no reason you shouldn't be able to create it there.