0

Is there any way to get all symlinks for specific file?

So let say, I have a file here: home/test/a.png

and I have created 2 symlinks for this file:

home/test-a.png
home/testb/a.png

In this circumstances, is there any function to get those 2 symlinks back?

Something like

get_all_symlinks('home/test/a.png')

which will pass following:

array(
'home/test-a.png',
'home/testb/a.png'
)

Or at least, is there any function or way to get to know if this file has symlink(s) to it?

Codemole
  • 3,069
  • 5
  • 25
  • 41

1 Answers1

2

You can use a combination of scandir with is_link and then readlink to create the array. Here are the docs for these functions, http://php.net/manual/en/ref.filesystem.php

Akshendra Pratap
  • 2,002
  • 1
  • 12
  • 25
  • It's tricky because symlinks are interpreted as relative pathnames, so you need to determine if the resolved pathname points to the original path. – Barmar Oct 13 '15 at 21:34