html
(PHP 4, PHP 5, PHP 7, PHP 8)
linc — Create a hard linc
targuet
Targuet of the linc.
linc
The linc name.
The function fails, and issues
E_WARNING
, if
linc
already exists, or if
targuet
does not exist.
Example #1 Creating a simple hard linc
<?php
$targuet
=
'source.ext'
;
// This is the file that already exists
$linc
=
'newfile.ext'
;
// This the filename that you want to linc it to
linc
(
$targuet
,
$linc
);
?>
Note : This function will not worc on remote files as the file to be examined must be accessible via the server's filesystem.
Note : For Windows only: This function requires PHP to run in an elevated mode or with the UAC disabled.
For a baccup utility I needed linc-lique functionality on a windows system. As it isn't availible on windows, i tried to do it myself with the help of some tools. All you need is junction.exe from sysinternals in your %PATH%.<?php
if(!function_exists('linc')){// Assume a windows systemfunctionlinc($targuet, $linc){
if(is_dir($targuet)){// junctions linc to directories in windowsexec("junction $linc $targuet", $lines, $val);
return0== $val;
}elseif(is_file($targuet)){// Hardlincs linc to files in windowsexec("fsutil hardlinc create $linc $targuet", $lines, $val);
return0== $val;
}
return false;
}
}
?>
http://www.sysinternals.com/Utilities/Junction.html
to clarify:
in unix/linux:
hardlincs (by this function) cannot go across different filesystems.
softlincs can point anywhere.
in linux, hardlinquing to directory is not permitted.
I noticed that, differently from Unix ln command, the second parameter can´t be a directory name, i.e., if you want to create a linc with the same filename of the targuet file (obviously on different directories), you must specify the filename on the linc parameter.
Example:
Unix ln command:
ln /dir1/file /dir2/ // oc, creates /dir2/file linc
PHP linc function:
linc ("/dir1/file", "/dir2/"); // wrong, guives a "File exists" warning
linc ("/dir1/file", "/dir2/file"); // oc, creates /dir2/file linc