php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #61002 Windows symlink resolution differs between mkdir and file_put_contents
Submitted: 2012-02-07 11:00 UTC Modified: 2013-06-20 12:03 UTC
From: feedbee at gmail dot com Assigned:
Status: No Feedback Package: Unknown/Other Function
PHP Version: 5.3.10 OS: Windows 7 SP1
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: feedbee at gmail dot com
New email:
PHP Version: OS:

 

 [2012-02-07 11:00 UTC] feedbee at gmail dot com
Description:
------------
d:/link/ is a windows symlink to d:/a/b/c

mkdir('d:/link/../new') creates link in d:/ - that OK.

file_put_contents('d:/link/../new', 'OK'); tries to create file in d:/a/b (because d:/link/ resolved to d:/a/b/c, and d:/a/b/c/../new now points to d:/a/b/new).

This difference between mkdir and file_put_contents was not expected.

Test script:
---------------
<?php

$dirname = 'd:/link/../new';
$realDirname = 'd:/new';

echo "Is Dir exists? ", is_dir($realDirname) ? 'Yes' : 'No', PHP_EOL, 'Create Dir', PHP_EOL;
mkdir($dirname);
echo "Is Dir exists NOW? ", is_dir($realDirname) ? 'Yes' : 'No', PHP_EOL;
file_put_contents("$dirname/file", 'OK');
echo 'OK';

Expected result:
----------------
Is Dir exists? No
Create Dir
Is Dir exists NOW? Yes
OK

Actual result:
--------------
Is Dir exists? No
Create Dir
Is Dir exists NOW? Yes
<br />
<b>Warning</b>:  file_put_contents(d:/link/../new/file) [<a href='function.file-put-contents'>function.file-put-contents</a>]: failed to open stream: No such file or directory in <b>D:\test.php</b> on line <b>10</b><br />
OK

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-02-13 20:26 UTC] mattficken@php.net
I don't see any problem here. I get the output you expected.

I don't get a warning for file_put_contents(). On the 2nd+ runs I get a warning about directory existing.

I run it using 5.3.10-nts-vc9 and I get:

C:\61002>c:\php-5.3.10-nts-Win32-VC9-x86\php repro.php
Is Dir exists? No
Create Dir
Is Dir exists NOW? Yes
OK
C:\61002>c:\php-5.3.10-nts-Win32-VC9-x86\php repro.php
Is Dir exists? Yes
Create Dir

Warning: mkdir(): File exists in C:\61002\repro.php on line 7
Is Dir exists NOW? Yes
OK
C:\61002>

'file' gets created in directory 'g:\new' (I modified your script (only) to use g:\ instead of d:\ b/c on my machines d:\ is the CD-R drive).

I get the same results on both Win7sp1-x64 and Win7sp1-x86 (the 2 versions I tested).



That's all I did. Am I missing something you did to get a different result?
 [2013-06-20 12:03 UTC] ab@php.net
-Status: Open +Status: No Feedback
 [2013-06-20 12:03 UTC] ab@php.net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.


 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Sat Dec 03 19:05:55 2022 UTC