codeigniter - 链接应用程序中的文件?

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.

  • The application is sitting at: domain.com/mysite/ci/
  • The files created in: domain.com/mysite/ci/_/files/ (I can create the file here, but can't link to download it
  • I would like to create the file in: domain.com/mysite/downloads/ (I cannot create the file here, but I can link stuff to it to download.

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.