Приглашаем посетить
Пришвин (prishvin.lit-info.ru)

Section 13.12.  Working with Links

Previous
Table of Contents
Next

13.12. Working with Links

Unix links come in two types: hard links , which are files, and symlinks (also known as soft links), which are pointers to other files. The difference is crucial: if you delete a hard link, you 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.

You can create hard links and symlinks in PHP using the link( ) and symlink( ) functions, both of which take a target and a link name as their only two parameters and return true if they were successful or false otherwise. For example:

    $result = link("/home/paul/myfile.txt", "/home/andrew/myfile.txt");
    if (!$result) {
            echo "Hard link could not be created!\n";
    } else {
            $result = symlink("/home/paul/myfile.txt", "/home/andrew/myfile.txt");
            if (!$result) {
                    echo "Symlink could not be created either!\n";
            }
    }

PHP also gives you the readlink( ) function that takes a link name as its only parameter and returns the target that the link points to. For example:

    $target = readlink("/home/andrew/myfile.txt");
    print $target;
    // prints /home/paul/myfile.txt


Previous
Table of Contents
Next