to clarify:in unix/linux:hardlinks (by this function) cannot go across different filesystems.softlinks can point anywhere.in linux, hardlinking to directory is not permited.
(PHP 4, PHP 5, PHP 7, PHP 8)
link — Crea un enlace duro
target
El objetivo del enlace.
link
El nombre del enlace.
Versión | Descripción |
---|---|
5.3.0 | Esta función ahora está disponible en plataformas Windows (Vista, Server 2008 o superiores). |
Ejemplo #1 Crear un simple enlace duro
<?php
$objetivo = 'origen.ext'; // Este es el archivo que ya existe
$enlace = 'nuevo_fichero.ext'; // Este es el nombre de fichero que quiere enlazar
link($objetivo, $enlace);
?>
Nota: Esta función no funcionará en ficheros remotos ya que el fichero debe ser accesible vía el sistema de ficheros del servidor para poder ser examinado.
Nota: Sólo para Windows: Esta función requiere que PHP se ejecute en un modo elevado o con el UAC deshabilitado.
to clarify:in unix/linux:hardlinks (by this function) cannot go across different filesystems.softlinks can point anywhere.in linux, hardlinking to directory is not permited.
For a backup utility I needed link-like 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%.<?phpif(!function_exists('link')){ // Assume a windows system function link($target, $link){ if(is_dir($target)){ // junctions link to directories in windows exec("junction $link $target", $lines, $val); return 0 == $val; }elseif(is_file($target)){ // Hardlinks link to files in windows exec("fsutil hardlink create $link $target", $lines, $val); return 0 == $val; } return false; }}?>http://www.sysinternals.com/Utilities/Junction.html
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 link with the same filename of the target file (obviously on different directories), you must specify the filename on the link parameter.Example:Unix ln command:ln /dir1/file /dir2/ // ok, creates /dir2/file linkPHP link function:link ("/dir1/file", "/dir2/"); // wrong, gives a "File exists" warninglink ("/dir1/file", "/dir2/file"); // ok, creates /dir2/file link