How to write data into .txt file in codeigniter

帅比萌擦擦* 提交于 2019-12-11 03:35:43

问题


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


回答1:


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

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



回答2:


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


来源:https://stackoverflow.com/questions/31072419/how-to-write-data-into-txt-file-in-codeigniter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!