Couldn’t open stream %s

Description

When opening a stream, or file, a mode of operation is needed.

There are several valid modes: ‘r’, ‘r+’, ‘w’, ‘w+’, ‘a’, ‘a+’, ‘x’, ‘x+’, ‘c’, ‘c+’, ‘e’. Check docs for details about them.

All other strings are not supported, and yield this error.

Example

<?php

//`+k' is not a valid mode for fopen
// k is not an open option
fopen($path, '+k');

//`+wr' is not a valid mode for fopen
// write-only w, read-only r and + are mutually exclusive
// w+, r+ and rw are all valid
fopen($path, '+wr');


?>

Solutions

  • Use only valid stream open modes.

See Also

In more recent PHP versions, this error message is now Couldn’t open stream: %s.