Writing files to the filesystem
If you're reading from a disk (as we have seen previously), you'll probably want to write to a disk. Now, we'll look at creating several types of files and writing them to a location on the disk.
How to do it...
We're going to amend the file:
/path/to/codeigniter/application/controllers/write_file.php
Amend /path/to/codeigniter/application/controllers/file/file.php
to reflect the following:
public function write() { // Set data $data_to_write = 'This is text which will be written to the file'; // Define path for file $path = "/path/to/write/to/with/filename.extension"; if (!write_file($path, $data_to_write)) { // Error echo 'Error writing to file: ' . $path; } else { // Everything worked echo 'Data written to '. $path; ...
Get CodeIgniter 2 Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.