php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #13292 file_exists works with UNC names
Submitted: 2001-09-13 15:55 UTC Modified: 2004-10-31 21:11 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: Helmut dot Himmelstoss at t-online dot de Assigned:
Status: Closed Package: Documentation problem
PHP Version: 4.1.1 OS: Windows NT/2000
Private report: No CVE-ID: None
 [2001-09-13 15:55 UTC] Helmut dot Himmelstoss at t-online dot de
On a Windows 2000 box with PHP and IIS5.0, create a page the calls the file_exists function on a
known machine\share\file

You will need to create a share on that machine or another.

For example :

if (file_exists("\\\\machine\\share\\test.txt") {
  echo "Exists<BR>";
} else {
  echo "Does not Exist<BR>";
}

The file_exists function will always return false.

The function works fine with drive letter associations, but not for UNC notation on win32.

You have closed this bug with id #6554.

But this bug is not fixed in 4.0.6

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-12-15 05:54 UTC] sander@php.net
Markus noted that you should always use double backslashes (or single slashes): "\\\\computername\\share\\filename"

BTW: sorry for the typo Christoph... ;)
 [2002-02-12 16:44 UTC] dadrewa at characterlink dot net
I'm using IIS 5.0 on Windows 2000. I installed PHP 4.1.1 configured to be a CGI interpreter. I'm trying to require a file located on another W2K computer on our LAN with this code:
 
require '\\\\computername\\sharename\\functions.php';
 
However, when I try to execute this PHP script, I get this error:
 
Fatal error: Failed opening required '\\computername\sharename\functions.php' (include_path='..') in c:\inetpub\wwwroot\keygen\index.php on line 3

Supposedly this functionality is supported with PHP 4.1.1, but I'm not sure why it isn't working for me. The share is a local share and full access is granted to everyone.
 [2002-04-29 04:14 UTC] manuzhai@php.net
Have you tried the //computername/share/filename syntax?
 [2002-04-29 11:22 UTC] Helmut dot Himmelstoss at t-online dot de
Yes, this functionality are ok.
But only when the PC is trusted in a dom?ne and you are using a domain-user.
 [2002-04-30 07:29 UTC] christoph dot grottolo at gmx dot net
In IIS you can check the option 'check that file exists' in the IIS Admin interface on the panel where you enter the file extensions (.php -> c:\php\php.exe). Then IIS will check the permissions and open the file for php.

The anonymous webserver account (usually IUSER_MACHINENAME) must have appropriate permissions on the remote share. If not IIS will check if the remote user is a domain user with permission to access the share, but this only works if the remote user is in the same or in a trusted domain AND uses MSIE AND NTLM authentication is enabled in IIS.

PHP as CGI in IIS starts on a local account and cannot access remote shares itself.

I've been asked questions about this issue quite often, maybe the correct settings should be explained in the manual.

Christoph
 [2002-04-30 07:40 UTC] mfischer@php.net
Sounds reasonable as this kind of things keep coming more often recently. Marking as documentation problem
 [2002-04-30 08:06 UTC] christoph dot grottolo at gmx dot net
Addition to my previous post:

If you use Apache and PHP as CGI under Windows and install it as a service, you have to make it run under a domain account to let PHP access remote shares (check in control panel -> services). Usually it's run under the local system account.

I think this is also valid if you run PHP as an apache module but I didn't test.

Maybe this should also go into the documentation.

Christoph
 [2002-06-02 15:03 UTC] k.schroeder@php.net
This bug has been fixed in CVS. You can grab a snapshot of the
CVS version at http://snaps.php.net/. In case this was a documentation 
problem, the fix will show up soon at http://www.php.net/manual/.
In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites.
Thank you for the report, and for helping us make PHP better.


 [2004-08-25 09:17 UTC] paul dot yau at travelex dot com dot au
You have to change the 
Go to Internet Information Services, locate your php file, go to the properties of the file, Go to File security tab, 
Edit -> Anonymous access and authetication control

2 methods: 
first: Untick "Anonymous Access" and leave "Integrated Window Authentication" ticked

second: Tick Anonymous Access, edit and change the user. 
The user that's currently listed may be restricted to certain access. 


The problem i had was similar to everyone elses. 

Here's a small script to check that the share works:

Where:
it-56a is the server
Prod-Temp is the share name
and Temp is the folder in the share name

<?PHP	//UNC connection
	$path = "\\\\it-56a\\Prod-Temp\\Temp";

	if(file_exists($path))
	{
		echo "$path exists<br>";
	}
	else 
		echo "Cannot find $path<br>";

	

?>


So i don't think this is a bug, it's more of an IIS setting.
 [2004-08-25 09:24 UTC] derick@php.net
This last comment is something for the FAQ i think...
 [2004-10-31 21:11 UTC] didou@php.net
FAQ entry added, thank you Paul
 [2020-02-07 06:11 UTC] phpdocbot@php.net
Automatic comment on behalf of didou
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=f7de6d598bc088ac34e74351f0e9c8059c338987
Log: fix #13292 : added an FAQ entry on accessing sharing files under Windows
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Jun 26 18:01:31 2024 UTC