Can PHP's symlink() create a relative symbolic link?


Can PHP's symlink() create a relative symbolic link?



If I want to create a symbolic link in PHP I can use the symlink()-command. However, I can only seem te create absolute links using this method. For example:


symlink()



If I do ln -s ../bar ./bar in path/to/foo a relative symbolic link to ../bar is created in pat/to/foo. Now If I try to achieve the same thing in PHP:


ln -s ../bar ./bar


path/to/foo


../bar


pat/to/foo


symlink('path/to/foo', '../bar')



It does not create a symlink pointing to ../bar in path/to/foo. I also tried:


../bar


path/to/foo


chdir('path/to/foo');
symlink('../bar', './bar');



But also with no success. Can relative symbolic links be created using native PHP?





I can create relative symlinks from Php. Argument order matters.
– Progrock
Jul 2 at 13:50






First the target, then the link name (as in bool symlink ( string $target , string $link )) Neither ../bar nor ./bar are not valid names for the link
– marekful
Jul 2 at 13:51


bool symlink ( string $target , string $link )


../bar


./bar





'./bar' and '../bar' as the link argument works on my system.
– Progrock
Jul 2 at 13:51



'./bar'


'../bar'





Do you have write access to the write access to the target dir? Also I did some testing in php's interactive terminal. I could create a link. Then I went to a different terminal and deleted the link. I count not create the link in the interactive terminal. Php thought the file was still there. If I was in the same php terminal I could create, delete, then create the link without a problem.
– Jason K
Jul 2 at 14:04









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

api-platform.com Unable to generate an IRI for the item of type

How to set up datasource with Spring for HikariCP?

Display dokan vendor name on Woocommerce single product pages