Codeigniter:write_file()返回false

时间:2016-11-05 09:48:23

标签: javascript codeigniter writefile

/srv/www

变量public function ExportCSV() { // THIS PART IS WORKING $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); // data IS CORRECT // THIS PART NOT WORKING: write_file() returns false if ( ! write_file(APPPATH."/assets/media/upload/tamp.csv", $data, 'r+')) { echo 'Unable to write the file'; } else { echo 'File written!'; } } 包含正确的输出,但$data返回write_file()

目录false位于codeigniter项目的主目录中。

我的问题是:

  • 此函数是否返回false,因为我没有权限在此目录中写入?
    • 如果是,我该怎么办?
  • 我应该在哪个目录中编写此文件,因为我希望将其公开?

1 个答案:

答案 0 :(得分:0)

使用write_file创建文件时,请确保您的文件夹/目录位于您要创建文件的位置

然后我建议使用FCPATH      $ data ="一些文件数据&#34 ;;

 if (write_file(FCPATH . '/document/text.txt', $data) == FALSE)
 {
     echo 'Unable to write the file';

 } else {
     echo 'File written!';                           
 }

我的目录      应用

 document

 system

 index.php