Getting filename (or deleting file) using file handle

后端 未结 4 1783
感情败类
感情败类 2020-12-08 01:46

Is there a possibility to obtain filename from file handle? Or how can I delete file having only a handle?

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-08 02:18

    Nyes. Afaik there is no function in PHP to that directly. But on Linux, you can do

    $fp = fopen('somefile', 'r');
    $stat = fstat($fp);
    $inode = $stat['ino'];
    system("find -inum $inode", $result);
    echo $result;
    

    This is untested so it might need tweaking.

    EDIT Apparently, there is a simpler solution.

提交回复
热议问题