php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #40163 UNC Path not working
Submitted: 2007-01-19 01:00 UTC Modified: 2013-01-08 07:20 UTC
Votes:17
Avg. Score:4.6 ± 0.6
Reproduced:14 of 14 (100.0%)
Same Version:8 (57.1%)
Same OS:9 (64.3%)
From: coyle at washpenn dot com Assigned: pajoye (profile)
Status: No Feedback Package: Directory function related
PHP Version: 5.3 OS: Windows 2003
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2007-01-19 01:00 UTC] coyle at washpenn dot com
Description:
------------
Using UNC path to save out a file in PHP 5.1.6 and everything works great.  Upgraded to PHP 5.2.0 today and the UNC will not work anymore.

Reproduce code:
---------------
$path = '\\\\server\\share\\directory\\'

if(is_dir($path)) {
   print 'directory exists';
} else {
   print 'directory does not exists';
}

Expected result:
----------------
directory exists

Actual result:
--------------
directory does not exists

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-01-19 08:08 UTC] tony2001@php.net
Not enough information was provided for us to be able
to handle this bug. Please re-read the instructions at
http://bugs.php.net/how-to-report.php

If you can provide more information, feel free to add it
to this bug and change the status back to "Open".

Thank you for your interest in PHP.



 [2007-01-19 13:05 UTC] coyle at washpenn dot com
Better Example:

$path = '\\\\server\\share\\directory\\';

mkdir($path, 0770);

Warning: mkdir() [function.mkdir]: Invalid argument in <file> on line <line>
 [2007-01-19 14:09 UTC] tony2001@php.net
Double slashes are needed only with double quotes, because  "\x" means an escape character.
 [2007-01-19 14:27 UTC] coyle at washpenn dot com
$path = "\\\\server\\share\\directory";
or
$path = '\\server\share\directory';

Doesn't matter which I try ... I've tried many different combinations to produce the path in both 5.2.0 or 5.2.1 RC4-dev and none of them work.  Everything was fine in php <= 5.1.6
 [2007-01-19 14:33 UTC] coyle at washpenn dot com
Above:
    $path = '\\server\share\directory'; 
Should be:
    $path = '\\\\server\share\directory';

I am running out of things to try here.  When I print $path, I get a valid UNC path with no spaces anywhere but I still get the error above.
 [2007-01-20 22:48 UTC] edink@php.net
You do need to escape \ even under single quotes, so your first example is fine:

$path = '\\\\server\\share\\directory\\';

Are you running PHP under a web server? This sounds to me like permissions issue? Could you try running php.exe from command line and see if the result is any different.
 [2007-01-28 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".
 [2008-03-06 13:20 UTC] brianelley at gmail dot com
I don't know why this is was not continued by Coyle, but, this bug is still persisting even today. I am bound with this setup because of some other packages but I am unable to create folders or files on a network. This is really critical for the application. 

Can some one please reopen this bug as this is really urgent and its been a week that I am struggling with this. 

Brian.. brianelley@gmail.com
 [2008-05-13 15:47 UTC] julienlembo at free dot fr
I exerience the same problem.
My UNC path is correct but is_dir function is in trouble
 [2008-07-07 14:39 UTC] abaranenko at gmail dot com
I have the same problem.
We have tried different settings:
file://10.1.1.7 (shared folder)
\\ 2 bars
\\\\ 4 bars
All the settings possible, no been successful.
Use PHP 5.2.5. Below the 5.1 versions work.
	
No command operates on a network:
is_dir, file_exists.

Help
 [2008-07-07 19:11 UTC] abaranenko at gmail dot com
It did not work with version 2.5.7
Still unresolved.
I've tried many different combinations.
The shared directory with this ALL permission.
PS.: My English is bad bad.
 [2008-07-15 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".
 [2010-09-13 12:02 UTC] as at 24h dot de
Still unresolved in PHP 5.3.1
 [2010-09-13 12:53 UTC] pajoye@php.net
-Status: No Feedback +Status: Feedback -PHP Version: 5.2.0 +PHP Version: 5.3 -Assigned To: +Assigned To: pajoye
 [2010-09-13 12:53 UTC] pajoye@php.net
Try with 5.3.3, it works just fine here.
 [2010-11-26 08:53 UTC] hjan at libero dot it
PHP 5.3.3, windows 2008 R2, IIS 7.5.
This simple page:
<?php
$path = '\\\\server\\share\\';

$f = fopen($path . "somefile.txt", "w") or die ("can't open");
fwrite($f,"AAAAA"); 
print  'wroted-----';
fclose($f);

if(is_dir($path)) {
   print 'directory' . $path . 'exists';
} else {
   print 'directory' . $path . ' does not exists';
}
?>

return me PHP Warning: fopen(\\server\share\somefile.txt) [function.fopen]: failed to open stream: Invalid argument in C:\xxx\xxx\moodle\testdir.php on line 4 

If I comment the write function I obtain :
directory\\server\share\ does not exists
 [2010-11-26 12:33 UTC] pajoye@php.net
Please try using 5.3.4RC1.
 [2010-11-26 16:33 UTC] hjan at libero dot it
still no luck with 5.3.4RC1
php[4452]
PHP Warning:  mkdir() [<a href='function.mkdir'>function.mkdir</a>]: Invalid argument in C:\ETT\SITI\moodle\lib\setuplib.php on line 167
 [2010-11-26 18:16 UTC] pajoye@php.net
Not sure what C:\ETT\SITI\moodle\lib\setuplib.php is, but mkdir & co work just fine here (various windows). Please provide a small script with an explanation of your configuration (OS version where php runs, OS where the UNC target is).
 [2010-11-26 19:37 UTC] hjan at libero dot it
Here the SO as showed by phpinfo : 
Windows NT W-WEB01 6.1 build 7600 (Unknow Windows version Standard Edition) i586 
it's a Windows 2008 R2 Standard
IIS application pool runs with a domain administrator account. Share runs on another server, W2003 STD, everyone users has full rights on both share permission and physical folder permission.
With this test page named testdir.php:
<?php
$path = '\\\\ett2\\tempdb\\';


$f = fopen($path . "somefile.txt", "w") or die ("can't open");
fwrite($f,"AAAAA"); 
print  'wroted-----';
fclose($f);


if(is_dir($path)) {
   print 'directory' . $path . 'exists';
} else {
   print 'directory' . $path . ' does not exists';
}
?>
I obtain "can't open" on the web page and this message on the event log:
The description for Event ID 2 from source PHP-5.3.4RC1 cannot be found. Either the component that raises this event is not installed on your local computer or the installation is corrupted. You can install or repair the component on the local computer.

If the event originated on another computer, the display information had to be saved with the event.

The following information was included with the event: 

php[3852]
PHP Warning:  fopen(\\ett2\tempdb\somefile.txt) [<a href='function.fopen'>function.fopen</a>]: failed to open stream: Invalid argument in [sitephysicalpath]\testdir.php on line 5

Let me know if you need more information or if i could help with more test.
Regards,
Gianluca
 [2010-12-03 21:25 UTC] v-ryanbi at microsoft dot com
I cannot replicate this bug. Using the following script under IIS 
(with and without fastcgi.impersonate), under Apache2.2, and via 
CLI, all with recommended INI settings for both 5.3.4RC2 and 
5.2.15RC2, I get expected output:

<?php
$share = '\\\\win7-share-af04\\share';
echo 'current user: '; var_dump( get_current_user() );
 
echo '---TEST-ONE---'."\n";
$targets = array(
        'exists' =>'test_folder',
        'missing'=>'not_here',
        'file'=>'foo.txt',
);
foreach( $targets as $name => $target ) {
        echo $name."\n";
        $path = $share . DIRECTORY_SEPARATOR . $target;
        echo '  path:   '; var_dump( $path );
        echo '  is_dir: '; var_dump( is_dir( $path ) );
}
echo '---TEST-TWO---'."\n";
$bartxt = fopen( ( $share . DIRECTORY_SEPARATOR . 'bar.txt' ), "w" ) 
  or false;
if( !$bartxt ) {
        echo 'failed to open stream';
} else {
        fwrite( $bartxt, 'FUBAR '.time() );
        fclose( $bartxt );
        echo 'wrote file.';
}?>

Example result (IIS with impersonation):

---TEST-ONE---
exists
  path:   string(43) "\\win7-share-af04\share\test_folder"
  is_dir: bool(true)
missing
  path:   string(40) "\\win7-share-af04\share\not_here"
  is_dir: bool(false)
file
  path:   string(39) "\\win7-share-af04\share\foo.txt"
  is_dir: bool(false)
---TEST-TWO---
wrote file.

The file is created properly and is_dir reports accurately in 
all scenarios, except that which I don't have permission to see 
the share or the share is inaccessible. Have you tried using 
procmon to see the request for the file and the filesystem's 
response?
 [2013-01-08 07:20 UTC] pajoye@php.net
-Status: Feedback +Status: No Feedback
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Fri Aug 07 13:01:24 2020 UTC