php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48535 file_exists returns false if the file path is a symlink
Submitted: 2009-06-12 07:32 UTC Modified: 2009-09-28 20:25 UTC
Votes:2
Avg. Score:4.0 ± 1.0
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:2 (100.0%)
From: tobias dot burger at rolmail dot net Assigned: pajoye (profile)
Status: Not a bug Package: Filesystem function related
PHP Version: 5.3.0RC3 OS: win32 only - Windows Server 2008
Private report: No CVE-ID: None
 [2009-06-12 07:32 UTC] tobias dot burger at rolmail dot net
Description:
------------
file_exists returns false if the file path is a symlink

Reproduce code:
---------------
# d:\myfolder\test.php
> mklink /D c:\inetpub\wwwroot\myfolder d:\myfolder

file_exists('c:\inetpub\wwwroot\myfolder\test.php')


Expected result:
----------------
true

Actual result:
--------------
false

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-06-12 08:00 UTC] tobias dot burger at rolmail dot net
Correction: file_exists does ALWAYS return false, even for normal file pathes
 [2009-06-12 09:17 UTC] dsp@php.net
Please check if you have the correct permissions.
 [2009-06-12 09:21 UTC] pajoye@php.net
c:\php53rc3tsvc9x86> php -r "var_dump(file_exists('news.txt'));"
bool(true)

c:\php53rc3tsvc9x86> php -r "var_dump(file_exists(realpath('news.txt')));"
bool(true)

c:\php53rc3tsvc9x86> php -r "var_dump(file_exists(realpath('news123.txt')));"
bool(false)

same with VC6 builds.

I suspect David is right, the console may be run under a user not having the permissions to access c:\inetpub (5.3 has ACL supports now and actually returns the right info).
 [2009-06-12 09:25 UTC] tobias dot burger at rolmail dot net
User group EVERYONE has full permissions.
Other operations are working on that file:
e.g. include_once, file_get_contents
 [2009-06-12 09:29 UTC] pajoye@php.net
I use 2008 as well and it works fine. Can you add perms for your user specifically and test again?
 [2009-06-12 09:51 UTC] tobias dot burger at rolmail dot net
detailed system information
* Windows Server 2008
* IIS7 with Fast-CGI installed
* PHP5.3 ((5.3.0RC3) VC9 non thread safe from http://windows.php.net/qa/ (tried also VC6 and thread safe version)

The problem occurs only if executing the script from the web server.
I run the same script from the console and it works.

The permissions are set correctly (full permissions to everyone), as I can read and modify the file via PHP (running on IIS).
 [2009-06-12 09:58 UTC] pajoye@php.net
I use 2008 as well and it works fine. Can you add perms for your user
specifically and test again? take #2
 [2009-06-12 10:15 UTC] tobias dot burger at rolmail dot net
I've set the setting fastcgi.impersonate in php.ini to 1 (like recommendet in the documentation).
If I set it to 0 it works.
 [2009-06-12 10:17 UTC] pajoye@php.net
thanks for the update, I have to figure out what's wrong.
 [2009-06-15 17:02 UTC] pajoye@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5.3-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/

A fix has been applied to 5.3, please try it
 [2009-06-16 06:59 UTC] tobias dot burger at rolmail dot net
Now it works!

But realpath doesn't work for symlinked pathes anymore (it returns false).
Tried the RC3 realease again and there it works.
Has it something to do with the actual fix or should I open a new bug submission?
 [2009-06-17 21:18 UTC] pajoye@php.net
realpath works here (all tests machine) with symlink. Do you have an example (path used, dir or files?, etc.)
 [2009-06-18 08:16 UTC] tobias dot burger at rolmail dot net
I have a deep folder structure. For example i made a symlink (mklink /d) from a folder located on drive d: to a folder on drive c:

D:\root\web\wwwtypo35 -> C:\inetpub\wwwtypo35

If I call now realpath() for "C:\inetpub\wwwtypo35\Packages\Global\FLOW3\Classes\Package\Package.php" it returns false on the latest snapshot version of PHP. If I try the RC3 release it works and the function returns the full path.

Maybe the bug exists because I made a symlink to a path on another drive?
 [2009-07-02 15:09 UTC] patrick at procurios dot nl
We have the same problem on our Windows Vista developer machines. Links were made with the tool junction.exe (because the links need to work on both Windows XP and Windows Vista).

The problem was fixed in Vista when the old links were replaced by new mklink links.

We haven't tried PHP 5.3 on XP yet.
 [2009-07-02 15:40 UTC] pajoye@php.net
symlink are not junctions!

use mklink to create symbolic or hard links.
 [2009-07-10 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2009-09-28 20:25 UTC] pajoye@php.net
See #48746 for further comments or feedback.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 13:01:29 2024 UTC