PHP-如何每周处理/保存文件

我需要通过添加文件来处理文件,然后将其另存为单独的每周文件。

每月进行一次很容易,我的工作如下:

// Set variables
$month = date('m');
$year = date('Y');
// Load previous file content
$newreportfile = file_get_contents('/var/www/html/reports/' . $year . "_" . $month . "_report.csv");
// Add new content
$file_to_write = $newreportfile . $report_log;
// Write file back
file_put_contents('/var/www/html/reports/' . $year . "_" . $month . "_report.csv",$file_to_write);

将其全部保存在月度文件中效果很好,但是我该如何将其保存为每周格式,特别是在一周中的特定日期特定时间(星期日23:59:59)中断文件)?

任何关于最佳方法的指导都将受到赞赏。

谢谢。

woshisanbi 回答:PHP-如何每周处理/保存文件

您可以只使用以下代码。新的月份开始时,它将创建并写入新的月份文件,否则它将追加到当前月份的文件中。

每月保存一次,

file_put_contents('/var/www/html/reports/' . date("Y_m") . "_report.csv",$content,FILE_APPEND);

或每周保存一次,

file_put_contents('/var/www/html/reports/' . date("Y_W") . "_report.csv",FILE_APPEND);
本文链接:https://www.f2er.com/3111136.html

大家都在问