• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
write

#1
Hi,

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

Code:
public function ExportCSV()
{
    $this->load->dbutil();
       $this->load->helper('file');
       $delimiter = ',';
       $newline = "\n";
       $enclosure = '"';
       $filename = "tamp.csv";
       $query = "SELECT politician.id, politician.ident, party.abbr, politician.id_image, politician.name, politician.surname, politician.personal_birth, politician.home_city, politician.political_function  
          FROM politician
          INNER JOIN party
          WHERE party.id = 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';
    }
    else
    {
        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
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.