2015-06-26 60 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!'; 
}