文字

用户评论:

[#1] Anonymous [2009-10-16 01:54:56]

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.

[#2] stephane AT baladeauboutdumonde DOT com [2007-08-06 11:45:07]

Make link recursively :
<?php
function makeRecusLink($orig$dest)
{
    if (
is_dir($orig)) {
        if (
substr($orig, -1) != '/') {
            
$orig .= '/';
        }

        
$handle opendir($orig);

        while (
false !== ($file readdir($handle))) {
            if (
$file != '.' && $file != '..') {
                
$path $orig.$file;

                if (
is_file($path)) {
                    @
link($path$dest.'/'.$file);
                } else if (
is_dir($path)) {
                    @
mkdir($dest.'/'.$file0755);                    
                    
makeRecusLink($path$dest.'/'.$file);
                }
            }
        }
    }
    
    
closedir($handle);
}
?>

[#3] Jasper Bekkers [2006-08-02 07:16:51]

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%.

<?php
if(!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 
== $val;
        }elseif(
is_file($target)){
            
// Hardlinks link to files in windows
            
exec("fsutil hardlink create $link $target"$lines$val);
            return 
== $val;
        }
        
        return 
false;
    }
}
?>


http://www.sysinternals.com/Utilities/Junction.html

[#4] Guilherme Garnier [2006-04-25 11:32:10]

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 link

PHP link function:
link ("/dir1/file", "/dir2/");   // wrong, gives a "File exists" warning
link ("/dir1/file", "/dir2/file");   // ok, creates /dir2/file link

上一篇: 下一篇: