webCOMAND

stream_writer::open_file()

Convenience method to open a file stream.

Prototype

boolean open_file(string $filename, boolean $append = FALSE)

Parameters

  • filename - Name of the file to open for writing.
  • append - Optional parameter.  Specify TRUE to append writes to the end of the file if it already exists.  Default is FALSE.

Return

Always returns TRUE.  Throws a COMAND Exception upon failure.

Example

namespace \io_comand_file\stream_writer;

try {
    $out = new stream_writer();
    $out->open_file('test.txt');
    $out->write('Some text.');
    $out->close();
} catch(\io_comand\exception $e) {
    echo('File Write Error: ' . $e->getMessage());
}