In PHP, how do I check if a stream resource (or file pointer, handle, or whatever you want to call them) is either readable or writable? For example, if you\'re faced with a
Quite simple. Just call stream_get_meta_data($resource) from your script, then check the mode
array element of the return value:
$f = fopen($file, 'r');
$meta = stream_get_meta_data($f);
var_dump($meta['mode']); // r
And if you want to know if the underlying data is writable:
var_dump(is_writable($meta['uri'])); // true if the file/uri is writable