Skip to content

Symbolic links

Greg Bowler edited this page May 5, 2026 · 1 revision

GT\Sync\SymlinkSync creates a symbolic link from a source path to a destination path.

Use this when one public path should point at another directory or file without needing to copy the contents.

Link a directory

use GT\Sync\SymlinkSync;

$sync = new SymlinkSync(
	"data/upload",
	"www/data/upload"
);

$sync->exec();

If the parent directory for the destination does not exist, it is created.

Link a file

$sync = new SymlinkSync(
	"asset/logo.svg",
	"www/logo.svg"
);

$sync->exec();

The same class handles both files and directories.

Existing links

If the destination is already a symbolic link to the same source, the operation is skipped.

If the destination is a symbolic link to a different source, the old link is removed and a new one is created.

If the destination already exists and is not a symbolic link, symlink() fails and the destination path is added to the failed list.

Operation lists

After exec() has run, these methods describe the result:

$linkedFiles = $sync->getLinkedFilesList();
$linkedDirectories = $sync->getLinkedDirectoriesList();
$allLinked = $sync->getCombinedLinkedList();
$skipped = $sync->getSkippedList();
$failed = $sync->getFailedList();

Each call to exec() clears the previous lists before trying again.


Next, move on to command line to use the same functionality from the terminal.

Clone this wiki locally