I am trying to create a hard-link with PHP. I know there are three kinds of links: Symlinks, hard-links, and directory junctions (hard-links for directories).
In PHP a symlink is the symlink()
function, a hard-link is link()
, but what for a directory junction?
I need to use it for a web application, and a symlink is not enough for me.
Thanks
Directory junctions are an NTFS-specific feature. There are no directory junctions in Linux. There are directory-binding mounts (look for "The bind mounts"), which provide similar functionality, however they require root access.
You cannot create hard links (or "directory junctions") to directories in Linux, it is not supported by the operating system. I don't know if it is possible using link in Windows but it should be as easy as trying.
I had a similar issue, and as I was running specifically on Windows system, I did:
exec('mklink "' . $linkLocation . '" "' . $linkTarget . '" /J')
A successful result looked something like this:
Junction created for C:\...\... <<===>> C:\...\...
I use this simple function, it is working with windows.
<?php
function makeSymLink ($target, $link)
{
exec('mklink /j "' . str_replace('/', '\\', $link) . '" "' .str_replace('/', '\\', $target) . '"');
}
?>