Is there a possibility to obtain filename from file handle? Or how can I delete file having only a handle?
Space and inodes may not be returned to the system until the volume blog has processed the deleted blocks.
The file handle is used to identify the file in many function calls. Each file handle and file object is generally unique to each process that opens a file—the only exceptions to this are when a file handle held by a process is duplicated, or when a child process inherits the file handles of the parent process.
When you open a file, it gets loaded in the open file table this tables exists in the computer memory (RAM), after that all modifications made to that file are only saved to the same file loaded in that table and not the one on the disk, even if you delete your file from the disk it still exists in the open file table.
There is stream_get_meta_data. It works for a stream that you get from tmpfile(). If you call it on a regular file pointer then you might only get the basename.
$meta_data = stream_get_meta_data($stream_or_file_pointer); $filename = $meta_data["uri"]; echo $filename;
Example for tmpfile():
"/private/var/folders/v3/n54x13jx5v7610fw9dm0wcxm0000gn/T/phpCJvevP"
Example for fopen("somefile", "r"):
"test"
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With