php - PHP - How to process/save weekly files
问题描述
I need to process a file by adding to it, but then saving as separate weekly files.
It is easy to do monthly, which I am doing as follows:
// 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);
This works fine for keeping it all in a monthly file, but how could I do this to have it in a weekly format, specifically breaking the files on a particular day of week at a particular time (Sunday 23:59:59)?
Any guidance on the best way to do this would be appreciated.
Thank you.
解决方案
您可以使用以下代码。当新的月份开始时,它将创建并写入一个新的月份文件,否则它将附加到当前月份文件。
每月存起来,
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", $content, FILE_APPEND);
推荐阅读
- multithreading - 如何使用windbg在转储分析中每分钟检查哪个线程正在等待
- android - android studio-依次播放音频文件
- c# - UWP mapcontrol AltitudeReferenceSystem 未应用于地图项
- node.js - 生成过程关闭后无法删除文件夹
- python - 如果字符串不在另一个单项字符串列表中,则从列表中删除字符串
- python - 如何分别运行多输入 keras 模型?
- python - 如何避免 python 循环中的特定交互?我想跳过提到的代码 3 7 和 9 但它只删除了 3
- oracle - 语句未在 pl/sql 中打印
- go - 互斥锁如何与单例一起使用?
- http - Flutter/Dart http 客户端 - 内容类型标头发送两次