How to write data into .txt file in codeigniter

2019-08-08 20:45发布

I have a folder in assets name is login.My doubt is what how to set the path.

$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!';
}

No problem about the data but the path is wrong i set

my path is 'localhost/project/pro/application/assets/login/(specific .txt file)'

Output is Unable to write the file

2条回答
smile是对你的礼貌
2楼-- · 2019-08-08 21:09
$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!';
}
查看更多
狗以群分
3楼-- · 2019-08-08 21:23

Use APPPATH. It is the path up to your application folder

if ( ! write_file(APPPATH."assets/login/log_$todate.txt", $data))
查看更多
登录 后发表回答