Bug #68167 [NEW]: Can't create a relative symlink without changing dir

From: Date: Mon, 06 Oct 2014 14:34:44 +0000
Subject: Bug #68167 [NEW]: Can't create a relative symlink without changing dir
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-187887@lists.php.net to get a copy of this message
From:             nathan dot renniewaldock at gmail dot com
Operating system: Windows 7
PHP version:      5.4.33
Package:          Filesystem function related
Bug Type:         Bug
Bug description:Can't create a relative symlink without changing dir

Description:
------------
symlink() fails to create a relative link if the working dir is not the
same as where the link is going (works correctly on Linux). Relative
targets should be resolved from the dir the link will be. For now, my
workaround is calling mklink through shell_exec.

Test script:
---------------
<?php
file_put_contents("test.txt", time());

mkdir("a");

echo "symlink(): ";
symlink("..\\test.txt", "a\\1.txt") && print("success\n");

echo "\nmklink: ".shell_exec("mklink a\\2.txt ..\\test.txt");

echo "\nchdir(), symlink(): ";
chdir("a");
symlink("..\\test.txt", "3.txt") && print("success\n");


Actual result:
--------------
C:\php-test>php a.php
symlink(): PHP Warning:  symlink(): Could not fetch file
information(error 2) in C:\php-test\a.php on line 7

Warning: symlink(): Could not fetch file information(error 2) in
C:\php-test\a.php on line 7

mklink: symbolic link created for a\2.txt <<===>> ..\test.txt

chdir(), symlink(): success

C:\php-test>dir a
 Directory of C:\php-test\a
06/10/2014  15:21    <SYMLINK>      2.txt [..\test.txt]
06/10/2014  15:21    <SYMLINK>      3.txt [..\test.txt]


-- 
Edit bug report at https://bugs.php.net/bug.php?id=68167&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=68167&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=68167&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=68167&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=68167&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=68167&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=68167&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=68167&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=68167&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=68167&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=68167&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=68167&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=68167&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=68167&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=68167&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=68167&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=68167&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=68167&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=68167&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=68167&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=68167&r=mysqlcfg



Thread (3 messages)

« previous php.bugs (#187887) next »