note 74411 deleted from function.symlink by nlopess
| From: | nlopess@php.net | Date: | Sun, 15 Apr 2007 11:17:36 +0000 |
| Subject: | note 74411 deleted from function.symlink by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-125412@lists.php.net to get a copy of this message | ||
Note Submitter: egingell at sisna dot com
----
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 . '"');
}
?>