简体   繁体   中英

PHP: Error Accessing Network Directory

Helo there,

I'm trying to write an application that reads the contents of a folder mapped on the network, but I just can't figure what I'm doing wrong. The target server don't have Apache, IIS or nothing like that, but I think that doesn't matter, right? I can navigate in the folder without any problem using the Windows Explorer.

Anyway, here is my code:

<?php
error_reporting(-1);

$isFolder1 = opendir("\\\\MVM-VIRTUAL04\\");
$isFolder2 = opendir("\\\\MVM-VIRTUAL05\\WORK\\");
var_dump($isFolder1); //bool(false)
var_dump($isFolder2); //resource(3) of type (stream) 
?>

And it shows the following errors:

Warning: opendir(\\MVM-VIRTUAL04\,\\MVM-VIRTUAL04\) [function.opendir]: The specified path is not valid.. (code: 161) in xxx on line 4

Warning: opendir(\\MVM-VIRTUAL04\) [function.opendir]: failed to open dir: No error in C:\xampp\htdocs\Lab\fopen.php on line 4

bool(false) resource(3) of type (stream) 

As far that I know, both server have a very similar structure, but I really don't know what to do anymore. The XAAMP and the Apache in my machine are running as an Administrator in a Windows 7 64 Bits.

I've tried to use system , (because the server is restricted, but I have full access) but it also do not work.

system('net use X: "\\x-drive\public" password1 /user:username /persistent:no');
$isFolder(is_dir("x:/"));
echo($isFolder); //FALSE

You cannot access a network directory in PHP. If you're working in Linux, you can go around this by simply mounting the network drive to a folder and the OS will consider it "Local", but in Windows, it can't be done.

EDIT: Okay, this post here contradicts what I just said so my apologies for the false information:

PHP is_dir() returns false on Windows network drive

However, if it always returns false, maybe the folder isn't shared properly. Are you certain you didn't make a mistake in the folder name? You also have to run Apache as an administrator for it to work apparently.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM