$log_name = 'log/log' . date('Y-m-d') . '.txt';//定義要創建文件的位置
$ch = fopen($log_name,'a+'); //打開文件,‘a+代表以讀寫的方式打開’
fwrite($ch,$logs . ' ' . date('Y-m-d H:i:s') . "\r\n");//寫入文件fclose($ch);//關閉文件
}
fopen(filename,mode,include_path,context)
參數 | 描述 |
---|---|
filename | 必需。規定要打開的文件或 URL。 |
mode | 必需。規定要求到該文件/流的訪問類型。可能的值見下表。 |
include_path | 可選。如果也需要在 include_path 中檢索文件的話,可以將該參數設爲 1 或 TRUE。 |
context | 可選。規定文件句柄的環境。Context 是可以修改流的行爲的一套選項。 |
fwrite(file,string,length)
參數 | 描述 |
---|---|
file | 必需。規定要寫入的打開文件。 |
string | 必需。規定要寫入文件的字符串。 |
length | 可選。規定要寫入的最大字節數。 |
fclose(file)
參數 | 描述 |
---|---|
file | 必需。規定要關閉的文件。 |