如何将数据写入codeigniter中的.txt文件

时间:2015-06-26 11:47:38

标签: php codeigniter file-writing

我在资产名称中有一个文件夹是login.My怀疑如何设置路径。

$data=$id.'~'.$expense_type.'~'.$amount.'~'.$exp_date.'<br>';

$todate= date('Y-m-d');
echo $todate;
if ( ! write_file('.../assets/login/log_'.$todate.'.txt', $data))
{
echo 'Unable to write the file';
}
else
{ 
echo 'File written!';
}

数据没问题但路径错误我设置

  

我的路径是'localhost / project / pro / application / assets / login /(具体   .txt文件)'

输出无法写入文件

2 个答案:

答案 0 :(得分:4)

使用APPPATH。它是应用程序文件夹的路径

if ( ! write_file(APPPATH."assets/login/log_$todate.txt", $data))

答案 1 :(得分:0)

$data=$id.'~'.$expense_type.'~'.$amount.'~'.$exp_date.'<br>';
$todate= date('Y-m-d');
echo $todate;
if ( ! write_file(FCPATH .'/assets/login/log_'.$todate.'.txt', $data)){
   echo 'Unable to write the file';
}
else{ 
   echo 'File written!';
}
相关问题