CodeIgniter Forums
write - Printable Version

+- CodeIgniter Forums (
+-- Forum: Using CodeIgniter (
+--- Forum: General Help (
+--- Thread: write (/thread-66551.html)

write - scub - 11-03-2016


I have a problem with a simple code and I've searched for a solution all day long without any answer:

public function ExportCSV()
       $delimiter = ',';
       $newline = "\n";
       $enclosure = '"';
       $filename = "tamp.csv";
       $query = "SELECT, politician.ident, party.abbr, politician.id_image,, politician.surname, politician.personal_birth, politician.home_city, politician.political_function  
          FROM politician
          INNER JOIN party
          WHERE = politician.id_party
          LIMIT 10000";
       $result = $this->db->query($query);
       $data = $this->dbutil->csv_from_result($result, $delimiter, $newline, $enclosure);

       if ( ! write_file(APPPATH."/assets/media/upload/tamp.csv", $data, 'r+'))
        echo 'Unable to write the file';
        echo 'File written!';

The variable $path returns the correct output but the write_file() returns false. The directory /assets/ is in the main directory of the project.
So my questions are:
Is this function returning false because I don't have the permission to write in this directory ? If yes, what should I do ? In which directory should I write this file as I would like it public ?

Thank you  Angel