2015-06-26 56 views
1

我有一个资产名称为login的文件夹。我怀疑如何设置路径。如何在codeigniter中将数据写入.txt文件

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

有关数据,但路径没有问题是不对的我设置

我的路径是 '本地主机/项目/ PRO /应用/资产/登录/(具体 .txt文件)'

输出是无法写入文件

+0

你能不能给任何suggetions? – robins

+0

只是摆脱路径'... /'并将'assets'目录放置在'application'文件夹之外 – CodeGodie

回答

4

使用APPPATH。它是一个路径到你的应用程序文件夹

if (! write_file(APPPATH."assets/login/log_$todate.txt", $data)) 
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!'; 
}