2022年6月2日 星期四

php 以fopen,fwrite,fclose寫入檔案(log檔或txt檔)

$destination = __DIR__.'/logs/filename.log'; //指定檔案位置
$clog = fopen($destination,'a'); //開啟檔案,沒有的話就會新增一個
fwrite($clog,$someText."_".date("Y-m-d H:i:s")."\n"); //組合要寫入的內容,最後加上一個斷航符號\n
fclose($clog); //完成後關閉檔案

沒有留言: