2

The manual says

Note: For Windows only: This function requires PHP to run in an elevated mode or with the UAC disabled.

But on my Windows 8 machine I can run mklink /H without elevated privileges, so I don't understand why PHP would require this. On the other hand, if I run mklink without the H to create a symlink, I do require elevated privileges, although this isn't commented on in the PHP docs for symlink().

I don't have a windows PHP installation, so can't test it (and I wonder how this applies for windows 7, vista, or whatever). Are the docs wrong?

user2667066
  • 1,867
  • 2
  • 19
  • 30

2 Answers2

1

I tested it on my Windows 8.1 machine, and it appears to work fine (running via Apache/CGI)

<pre><?php
var_dump(file_exists('f1'));
var_dump(file_exists('f2'));

var_dump(touch('f1'));
var_dump(link('f1','f2'));

var_dump(file_exists('f1'));
var_dump(file_exists('f2'));

var_dump(file_put_contents('f1', 'test'));
var_dump(file_get_contents('f2'));

Output:

boolean false
boolean false
boolean true
boolean true
boolean true
boolean true
int 4
string 'test' (length=4)
Petah
  • 45,477
  • 28
  • 157
  • 213
  • Just to clarify, is it running as a Windows service? If so, then it's probably running with the "system" account privileges (basically super-user) – Jonathan Gray Nov 18 '14 at 02:05
  • @JonathanGray no, its running as a user process. Also tried `php -r "link('f1','f2');"` from a cmd window and it worked fine. – Petah Nov 18 '14 at 02:12
  • Oh, okay. It could be extended permissions on Windows 8.1 I'm assuming. – Jonathan Gray Nov 18 '14 at 02:15
1

You do not need to be running as an administrator in order to create a hard link. However, unlike in UNIX, you do need write access to the target of the link.

I would hazard a guess that the author of the document in question was attempting to create a hard link to a file to which only administrators had write access, and so incorrectly concluded that administrator access was necessary in order to create hard links.

Harry Johnston
  • 35,639
  • 6
  • 68
  • 158