PHP link() Function
In this chapter you will learn:
- Definition for PHP link() Function
- Syntax for PHP link() Function
- Parameter for PHP link() Function
- Return for
- Note on PHP link() Function
- Example - creates a hard link from the existing target with the specified name link
Definition
The link() function creates a hard link from the existing target with the specified name link.
Syntax
PHP link() Function has the following syntax.
link(target,link)
Parameter
Parameter | Is Required | Description |
---|---|---|
target | Required. | Target File |
link | Required. | Link to create |
Return
This function returns TRUE on success, or FALSE on failure.
Note
Unix links come in two types:
- hard links, which are files, and
- symlinks also known as soft links, which are pointers to other files.
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.
Example
creates a hard link from the existing target with the specified name link
<?PHP//j a va2 s . c om
$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";
}
}
?>
Next chapter...
What you will learn in the next chapter:
- Definition for PHP linkinfo() Function
- Syntax for PHP linkinfo() Function
- Parameter for PHP linkinfo() Function
- Return for PHP linkinfo() Function
- Note for PHP linkinfo() Function
- Example - Returns information about a hard link
Home » PHP Tutorial » PHP File Functions