|
46 | 46 | $month = $_GET["month"];
|
47 | 47 | // Format the file name based on the year and month
|
48 | 48 | $file_name = sprintf('%04d%02d', $year, $month);
|
| 49 | + $output_file_name = $file_name; |
49 | 50 | $charge_log_file = $charge_log_path . $file_name . ".json";
|
50 | 51 |
|
51 | 52 | // Attempt to load the charge log file for the specific month
|
|
66 | 67 | for ($month = 1; $month <= 12; $month++) {
|
67 | 68 | // Format the file name based on the year and month
|
68 | 69 | $file_name = sprintf('%04d%02d', $year, $month);
|
| 70 | + $output_file_name = sprintf('%04d', $year); |
69 | 71 | $charge_log_file = $charge_log_path . $file_name . ".json";
|
70 | 72 |
|
71 | 73 | // Append data from each month's charge log file if it exists
|
72 | 74 | if (file_exists($charge_log_file)) {
|
73 | 75 | $monthly_data = json_decode(file_get_contents($charge_log_file), true);
|
74 |
| - $charge_log_data = array_merge($charge_log_data, $monthly_data); |
| 76 | + if (is_array($monthly_data)) { |
| 77 | + $charge_log_data = array_merge($charge_log_data, $monthly_data); |
| 78 | + } |
75 | 79 | }
|
76 | 80 | }
|
77 | 81 | }
|
@@ -159,7 +163,7 @@ function formatEnergy($value)
|
159 | 163 |
|
160 | 164 | if (is_array($charge_log_data)) {
|
161 | 165 | header("Content-Type: text/csv");
|
162 |
| - header("Content-Disposition: attachment; filename=ChargeLog-" . $file_name . ".csv"); |
| 166 | + header("Content-Disposition: attachment; filename=ChargeLog-" . $output_file_name . ".csv"); |
163 | 167 |
|
164 | 168 | # Output CSV header
|
165 | 169 | $csv_header = newRow();
|
|
0 commit comments