PHP symlink() Function

Definition

PHP symlink() Function creates a symbolic link.

Syntax

PHP symlink() Function has the following syntax.

symlink(target,link)

Parameter

ParameterIs RequiredDescription
targetRequired.Target of the link.
linkRequired.The link name.

Return

This function returns TRUE on success, or FALSE on failure.

Note

The symlink() function creates a symbolic link from the existing target with the specified name link. This function does not work on Windows platforms.

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 symbolic link.


<?PHP/*  w  ww  .  jav a 2s  .c  om*/
      $result = link("/home/user1/myfile.txt", "/home/user2/myfile.txt");
      if (!$result) {
             echo "Hard link could not be created!\n";
      } else {
             $result = symlink("/home/user1/myfile.txt", "/home/user2/myfile.txt");
             if (!$result) {
                 echo "Symlink could not be created either!\n";
             }
      }
?>




















Home »
  PHP Tutorial »
    Function reference »




PHP Array Functions
PHP Calendar Functions
PHP Class Functions
PHP Data Type Functions
PHP Date Functions
PHP File Functions
PHP Image Functions
PHP Math Functions
PHP MySQLi Functions
PHP SimpleXML Functions
PHP String Functions
PHP XML Functions
PHP Zip Functions