Does the PHP link() command really require elevated privileges on Windows?

335 views Asked by At

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?

2

There are 2 answers

2
Harry Johnston On BEST ANSWER

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.

3
Petah On

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)