Google
 

Tuesday, December 25, 2007

Creates A Symbolic Link

Windows Vista has its own symlink program now (mklink). Hopefully future versions of PHP for Windows will have this function put it?

Anyway, this will work on Vista (assuming your PHP user has the proper permissions):
<?php
define('SYMLINK_FILE', 0);
define('SYMLINK_DIR', 1);
define('SYMLINK_JUNCTION', 2);
function symlink ($target, $link, $flag = SYMLINK_FILE) {
switch ($flag) {
case SYMLINK_DIR: $pswitch = '/d'; break;
case SYMLINK_JUNCTION: $pswitch = '/j'; break;
case SYMLINK_FILE:
default: $pswitch = ''; break;
}
// Change / to \ because it will break otherwise.
$target = str_replace('/', '\\', $target);
$link = str_replace('/', '\\', $link);
return exec('mklink ' . $pswitch . ' "' . $link . '" "' . $target . '"');
}
?>