The link() function creates a hard link from the existing target with the specified name link.
PHP link() Function has the following syntax.
link(target,link)
Parameter | Is Required | Description |
---|---|---|
target | Required. | Target File |
link | Required. | Link to create |
This function returns TRUE on success, or FALSE on failure.
Unix links come in two types:
Delete a hard link, delete the file unless there are other hard links pointing to the same file, whereas if you delete a symlink, the original file remains untouched.
We can create hard links and symlinks using the link() and symlink() functions, both of which take a target and a link name and return true if they were successful or false otherwise.
creates a hard link from the existing target with the specified name link
<?PHP//from ww w .ja v a 2 s . co m
$result = link("/home/user2/myfile.txt", "/home/user1/myfile.txt");
if (!$result) {
echo "Hard link could not be created!\n";
} else {
$result = symlink("/home/user2/myfile.txt", "/home/user1/myfile.txt");
if (!$result) {
echo "Symlink could not be created either!\n";
}
}
?>