PHP symlink() fails on Windows 7
Asked Answered
P

3

2

PHP symlink() function fails on Windows 7 with the error:

Warning: symlink(): Cannot create symlink, error code(3) in C:\xampp\htdocs\…\lib\model\doctrine\Website.class.php

It's a XAMPP server on with PHP 5.3.8.

From the symlink() documentation:

5.3.0 This function is now available on Windows platforms (Vista, Server 2008 or greater).

Any ideas/suggestions?

Pertinent answered 14/11, 2012 at 9:42 Comment(2)
Permissions issue maybe? Try with UAC turned off and Xampp running as administrator.Dugong
Not the case unfortunately, the user is an administrator, folder is writable.Pertinent
C
3

Might be a bug in PHP 5.3 according to this:

https://bugs.php.net/bug.php?id=48975

and this:

http://forum.wampserver.com/read.php?2,64011 (reply #2)

Maybe you could upgrade to PHP 5.4 and see if it works?

Cajun answered 14/11, 2012 at 10:15 Comment(3)
Thanks for the suggestion, we'll give it a run shortly.Pertinent
Absolute niceness, it worked! XAMPP update to the PHP version 5.4.7 fixed it. Thanks a lot Alex!Pertinent
Alex, if you have a spare minute, I'd appreciate if you took a look at another case/bug with symlinks on Windows 7 https://mcmap.net/q/1329677/-filetype-returns-dir-for-symlinks-on-windows-7/1373324 Could be that you've experienced this as well.Pertinent
Z
0

I use this

//symlink($target, $link);
exec('mklink /j "' . str_replace('/', '\\', $link) . '" "' . str_replace('/', '\\', $target) . '"');
Zagreus answered 4/6, 2015 at 12:43 Comment(1)
The option /j creates symlinks to folders - for files (as needed in this case) use /H instead - see: howtogeek.com/howto/16226/…Elocution
U
0

About PHP CLI on windows OS:
Do not forget to start the console with Run as Administrator else symlink will return false and raise the following error:

Warning: symlink(): Cannot create symlink, error code(1314)
Uptake answered 23/2, 2018 at 23:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.