如何检查文件句柄是否仍指向文件

Is there any way in PHP to test if a fileHandle resource still points to the file in the file system that it opened? e.g. in this code:

<?php

$filename = './foo.txt';
$fileHandle = fopen($filename, 'c');

$unlinked = unlink($filename);

if (!$unlinked) {
    echo "Failed to unlink file.";
    exit(0);
}

file_put_contents($filename, "blah blah");

// The file $filename will exist here, but I want to check that
// the $fileHandle still points to the file on the filesystem name $filename.
?>

At the end of that code, the fileHandle still exists but no longer references the file './foo.txt' on the filesystem. It instead still holds a reference to the original file that has been unlinked, i.e. it has no active entry in the filesystem, and writing data to the fileHandle will not affect the contents of the file called $filename.

Is there a (preferably atomic) operation to determine that $fileHandle is now 'invalid' in the sense that it no longer points to the original file?

查看全部
douchensi8625
douchensi8625
2015/05/11 15:26
  • file
  • php
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

1个回复