PHP. How to get file name open file handle


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
5 views
Problem. There is a function that generates a filename, writes it to the database and performs
return fopen($filename);

So any task as returned by the handler to the name of the open file. I have an adequate way to do this with PHP not found.

PS. Yes, the question is purely theoretical, problem I'll probably decide to rewrite the function to return in addition to the handler the name.
by | 5 views

4 Answers

0 like 0 dislike
He asked a question, he will respond. I had to dig in the manual, but the answer is found.
fopen returns a resource of type stream. And among the functions working with flow was the stream_get_meta_data function that returns an associative array. In this array is the uri parameter, which provides the given file name is associated with our handler.
by
0 like 0 dislike
As far as I know, it's impossible.
by
0 like 0 dislike
In Unix systems, the file and its name is different entities, so it is impossible. More precisely, it is possible to traverse the entire tree of directories, starting with /, and look for the name that corresponds to the inode, but it is quite a suboptimal solution.
by
0 like 0 dislike
In Linux so:
\r
/proc/PID/fd/@FD — this is the link to your file, for example here:
\r
\r
root@in:/# ps aux | grep nginx root 3267 0.0 0.0 28724 824 ? Ss Sep22 0:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf# ... root@in:/# cd /proc/3267/fd root@in:/proc/3267/fd# ls-l l-wx------ 1 root root 64 2010-12-02 14:52 2 -> /var/log/nginx/error.log ... 

2 — here, the file handle a numeric, one can see which file it points...
\r
PHP not tried it, but in the console it's easy.
by

Related questions

0 like 0 dislike
1 answer
asked May 21, 2019 by burov0798
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
110,608 questions
257,186 answers
0 comments
27,842 users