Page 1 of 1

Is it possible to determine the file name from file handle?

Posted: Mon Feb 11, 2008 11:03 pm
by Luke
I have a class that accepts either a file name or a file handle as the first arg in its constructor. Is it possible to determine the file's name based on the handle? I mean it's not really necessary that I know it, but it seems that it should be possible.

Re: Is it possible to determine the file name from file handle?

Posted: Mon Feb 11, 2008 11:08 pm
by Benjamin
I don't think there is a practical way, the handle is just a resource id for a file stream.

This may help you http://us3.php.net/manual/en/function.d ... .php#81013

Re: Is it possible to determine the file name from file handle?

Posted: Mon Feb 11, 2008 11:45 pm
by Christopher
Ok ... I am having a Unix flashback ... I am growing one of those amazing hacker beards as I type this ...

Code: Select all

$stat = fstat($fp);
exec("ncheck -i {$stat[1]}", $filename);
In Perl it is one line...

In APL I can do it in 14 characters...

Re: Is it possible to determine the file name from file handle?

Posted: Tue Feb 12, 2008 1:25 am
by Benjamin
Well I shaved a few days ago so that knocks me out of the game..