Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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 and read-only r are mutually exclusive
fopen($path, 'wr');


?>

Literal Examples

  • Couldn’t open stream: ‘+k’ is not a valid mode for fopen
  • Couldn’t open stream: Is a directory
  • Couldn’t open stream: Inappropriate ioctl for device
  • Couldn’t open stream: Invalid argument

Alternatives

  • Use only valid stream open modes.

In previous PHP versions, this error message used to be :ref:couldn't-open-stream-%s.