2012-07-28 49 views
0

可能重複:
In PHP, after assigning a file pointer resource to a variable with fopen(), how can I get the file name from the variable?如何獲取有關資源的更多信息?

例子:

$this->resource = fopen('c:\wamp\www\some_file.txt', 'a');

現在,如果我稍後再嘗試訪問$this->resource,在不同的方法獲得:

Resource id #51: stream

我可以得到實際的文件路徑嗎?

+0

你怎麼能不知道你打開的是什麼文件? – Gntem 2012-07-28 13:29:32

回答

2

與voodoo417 addtitional aswer,你可以得到關於這樣

$infos = pathinfo('/www/htdocs/inc/lib.inc.php'); 

echo $infos ['dirname'], "\n"; 
echo $infos ['basename'], "\n"; 
echo $infos ['extension'], "\n"; 
echo $infos ['filename'], "\n"; 

----------------------輸出的文件信息 - ------------------------

/www/htdocs/inc 
lib.inc.php 
php 
lib.inc 

//從php.net

也看到FileInfo的推廣。

1

這不是文件路徑,這是打開的文件上的鏈接。它正常工作。現在你可以使用這個資源(文件在這個上下文中)。