Current Location: Home> Latest Articles> PHP link() Function Tutorial and Example

PHP link() Function Tutorial and Example

M66 2025-06-29

PHP link() Function Tutorial

In PHP, the link() function is used to create a hard link. A hard link is a file system feature that allows multiple file paths to point to the same physical file.

Syntax

link(target, link)

Parameters

  • target - The target file path to link to. This parameter is required.
  • link - The name of the hard link, or the new file path. This parameter is required.

Return Value

The link() function returns TRUE on success, and FALSE on failure.

Example Code


<?php
   $file = 'new.php';
   $newlink = 'mynew';
   link($file, $newlink);
?>

Output

True

With the code above, you can create a hard link in PHP. The link() function is particularly useful in scenarios where you need to share files.

That concludes the detailed explanation of PHP's link() function. You can now use this function in your projects according to your needs.