TechniqueUse two associative arrays to keep track of the device and inode number of files that you have used: <?php function remember_file ($file_name) { list($dev, $ino) = stat ($file_name); clearstatcache(); return !($file_info[$dev . $ino]++) ? 1 : 0; } ?> CommentsFor two files to be the same, they must have the same device and inode number. Knowing this enables us to create a unique ID using the device and inode number, and then check whether any other file has the same device or inode number. One way to implement this function is as follows : <?php // $file_list contains a list of file to check // for uniqueness, if they are unique // we pass them off to the imaginary modify() function foreach ($file_list as $file) { remember_file ($file) and modify ($file); } ?> Another use for this might be reporting which files are the same in a list of files. Consider the following: <?php foreach ($file_list as $file_name) { list ($dev, $ino) = stat ($file_name); if ($file_info[$dev . $ino]++) { array_push ($similar_files, $file_name); } clearstatcache(); } ?> |