The last file operation that we will work with is logging. We will begin by looking at how information can be logged to web server logs and build a simple logging library that can be used across the application. Let's begin by using the error_log
function provided by PHP to log information into the web server logfiles. For this example, let's use the export action that we created in the last section to add a message that will be logged.
The following codec needs to be added to the controllers/students.php
file:
public function export(){ $data = $this->model->getStudents(); $handle = fopen(ROOT_DIR.'/assets/files/students.csv', 'w+'); foreach ($data as $student) { fputcsv($handle, array($student['student_id'], $student['first_name'], $student['last_name'], $student['address'],$student['city'],$student['state'])); } fclose($handle); header('Content-Disposition: attachment; filename="students.csv"'); header('Content-Type:application/csv'); readfile(ROOT_DIR...