4

Possible Duplicate:
How to check if a PHP stream resource is readable or writable?

Does PHP provide any function to check the access mode of file handle? Suppose I opened a file in read only mode.

 $file_handle = fopen('putty.log','r');

Can I check a particular handle's access mode in code?

Community
  • 1
  • 1
P K
  • 9,972
  • 12
  • 53
  • 99
  • What do you need this for? What's the [overall goal](http://meta.stackexchange.com/questions/66377/)? – outis Dec 25 '11 at 08:38
  • @outis frankly, no specific goal for now. one use may be 'restrict access to write mode handlers'. thanks for editing question :) – P K Dec 25 '11 at 08:43
  • Here's an earlier post with a solution and detailed explanation: http://stackoverflow.com/questions/5294305/how-to-check-if-a-php-stream-resource-is-readable-or-writable – Abbas Dec 26 '11 at 08:43

1 Answers1

5

A possible solution to find the mode:

Use function stream_get_meta_data:

$file_handle = fopen('putty.log','r');
$metadata = stream_get_meta_data($file_handle);
echo $metadata['mode'];

For more on the array returned read the manual.

ThinkingMonkey
  • 12,539
  • 13
  • 57
  • 81