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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

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

Post 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.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

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

Post 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
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

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

Post 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...
(#10850)
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

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

Post by Benjamin »

Well I shaved a few days ago so that knocks me out of the game..
Post Reply