|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #51369 add getFileByInode() function
Submitted: 2010-03-23 18:52 UTC Modified: 2010-03-23 19:12 UTC
From: opi88 at web dot de Assigned:
Status: Not a bug Package: *Directory/Filesystem functions
PHP Version: Irrelevant OS: ALL
Private report: No CVE-ID: None
 [2010-03-23 18:52 UTC] opi88 at web dot de
Imagine a CMS (or similar system) that links a picture to a text. When the picture is moved to a different location, the system cannot find and include the picture anymore.

There are two options for solving this issue:
(1) Update each database entry containing the picture path. Depending on where, how and how many times the picture is included, this can be very tedious.
(2) Provided there is a database (table) containing all files linked to and their paths, you have to update this db / table with the new picture path.

But why use an extra database (table) in (2) when there already is a database for files: The filesystem!? And both methods require you to execute the update manually.

With PHP, you can get a file's Inode, but you can't get a file (path) by providing an Inode. If you could, you'll might just link an Inode in your database instead of a path and you'll always have the correct picture path.

Thus, I request a getFileByInode() function, or extend the fileinode() function to be able to return a path on integer input.

Test script:
$inode = fileinode('/path/to/file.ext');
$path  = fileinode((int) $inode); // returns '/path/to/file.ext'


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2010-03-23 19:12 UTC]
-Status: Open +Status: Bogus
 [2010-03-23 19:12 UTC]
The inode is handled by the filesystem and we can't rely in anyway on it. It is only exposed as away to help debugging some issues. Many filesystems don't offer a reliable way to locate files by their inode.
 [2010-03-23 22:14 UTC] opi88 at web dot de
Well that's no good news. But what about the filesystems that support a "getFileByInode" – can you name some? And is there any other way to get a unique identifier of a file that doesn't change when a file is moved, and can be resolved both ways?

In case there is not: Any "best practice" suggestion?
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Jul 22 04:01:29 2024 UTC