File Library

IgnitedCMS ships with a variety of useful file helper utilities

$this->load->library('file');

Function reference

set
Parameters:

string $path - Sets the base file path for either reading or writing

Returns:

void

Return type:

void

$this->load->library('file');
$this->file->set('test.txt');

Function reference

mode
Parameters:

string either 'read' or 'write' - determines if you are either reading or writing files

Returns:

void

Return type:

void

$this->load->library('file');
$this->set('test.txt')->mode('read');

Function reference

readlines
Parameters:

none - reads the file each line at a time (only works with ASCII file types)

Returns:

void

Return type:

void

$this->load->library('file');
$this->set('test.txt')->mode('read')->readlines()->close();

(Echos file content to view, if file exists)

Important! Always make sure to use the close() method after reading or writing files!!

Please make sure you set the file path correctly, you can use global vars such as APPPATH and FCPATH

Function reference

write
Parameters:

string - Writes a string to a file

Returns:

void

Return type:

void

$this->file->set('foo.txt');
	$this->file
	->mode("write")
	->write('line1')
	->write('line2')
	->close();

Function reference

writeline
Parameters:

string - Writes string to file except add a newline

Returns:

void

Return type:

void

$this->file->set('foo.txt');
	$this->file
	->mode("write")
	->writeline('line 1')
	->writeline('line 2')
	->close();