搞定了,要给apache设一下登陆用户:
参考----
Secondly, the APACHE service must be set-up to take this user into account. If no user is specified, APACHE uses an anonymous user and this is where the problem/error message is coming from. One must go in control panel->administrative tools->services. One will see the list of services and must look for APACHE with Apache/2.X.X in the description. (For Wampserver, it will be called wampapache, and so on!) Right click on that and pop up the properties screen. In the tab LOG ON, there are 2 options: local system account and "this account" which will be a user specified account. This is where one must specify the USER_TEST and PASS_TEST.
----
还是没搞定,,,,网络驱动器的问题,在运行里面net use K: \\192.168.10.10\pictures /persistent:no 就可以创建成功;但是在php里执行 system('net use K: \\192.168.10.10\pictures /persistent:no'); 就不行~~~
再贴点个人认为这方面比较有用的资料
-----------
http://www.dynamicdrive.com/forums/showthread.php?t=27880
Prefered Solution: Map a network drive using PHP at the beginning of the script
This solution is taken from Matt Grimm's posts on the opendir() page of the manual at PHP.net
1) Ensure Apache (or IIS, or php.exe if your running the CLI) is running as an account that has permission to access the relevant resource (I think this is the major sticking point here, the SYSTEM account doesn't have access to mapped network drives!!, but this step alone does not solve the problem). I just ran it as "Administrator", but if you are worried about the (slight) security implications there, set up a new user account and run it under that. You can change this setting in Control Panel > Administrative Tools > Services, select the relevant service and get the properties, then select the "Log On" tab.
2) AT THE BEGINNING of your script, map the network drive with your PHP code, using the windows "net" command's "use" function (you can map network drives from cmd with this command as well... type "net /?" at a command prompt for a basic explanation of this powerful command).
Here's the line: (Matt Grimm got this slightly wrong)
Code:
system('net use Z: "\\servername\sharename" PASSWORD /user:USERNAME /persistent:no');
Notes:
Use the system() command, not exec(). No idea why, but it doesn't work if you use exec(), although the command executes successfully. I haven't tried passthru(), but then why you would use it in this context I don't know...
You can use any unused drive letter. "Z:" is just an example.
If your share name contains a space, you MUST surround the path in the command with double quotes. It's good practice to do this when specifying any path for a Windows command. You must also keep the single quotes in the PHP command, and you not need to escape any back slashes. You can use an IP address instead of a name for the server if you wish.
Yes, it goes password, then username. Also there is no "/password" tag. Wierd, I know, but that's Microsoft for you.
Obviously there is a bit of a security issue with storing the password in your code, essentially in plain text, so here is a nice (albeit long) tutorial on a reversible password encryption method for PHP.
The "/persistent:no" part is essential. The network drive you map from PHP will not be visible in explorer, even if you specify your account as the logon account for Apache. If you don't turn "/persistent" off then it is still there, invisible, after a reboot, and the re-mapping attempt when you run the script again gets an error. You can, however, run the script multiple times during one session in Windows/PHP (ie one boot) without the error.
3) You can now access your network drive from a PHP command! Remember to escape any back slashes ( \ becomes \\ ) or you can just use forward slashes...
Z:/an/example/path
...is perfectly valid. (take note, because this makes writing cross-plaform scripts a lot easier and helps you avoid all those "spent an hour trying to find the problem and forgot to escape something" incidents)
This solution has been tested
with: Apache/2.0.63 (Win32) PHP/5.2.8
on: Windows XP Professional SP2/SP3, Windows Server 2003 R2 (various editions)
However, since the issue is basically an NT auth problem, this should work with any version of PHP (including command line) and any NT based OS.
--------------------------------------------------------------------------------
Last edited by DaveRandom; 03-30-2009 at 09:31 PM.
发完帖子就在这里找到了,,,
http://php.net/manual/en/function.opendir.php
---------------
matt
21-Feb-2009 10:50
I tried it as in the post before described, but it still won't work. Maybe cause i'm using an Apache-Server on Windows 2003 Server.
Now, i found a way that it works and i got access to the share. First of all, you need to set the run user for Apache to a user that has access to the share (see in post before).
Then map your drive in the php script before you read the dir:
system('net use K: \\servername\sharename /user:username password /persistent:no');
$share = opendir('\\\\servername\\sharename');
....
--------------
mana at averna dot com
07-Dec-2007 11:02
I was trying to access network drives using this opendir function. I read so many posts saying that it was almost impossible to access a network drive and finally, I found the answer; there are 2 steps to be followed to access a network drive with PHP either on the same machine or another machine.
But first of all, here's the error I was getting:
Warning: opendir(\\server\folder1\sub_folder) [function.opendir]: failed to open dir: No error in C:\wamp\www\PMOT\v0.1\REPORT_MENU\index.php on line 17
Firstly, one must make sure that the folder \\server\folder1\sub_folder can be accessed by a user, let's say USER_TEST with a password PASS_TEST. By setting properties to this folder, one can add this given user with the correct password (USER_TEST with PASS_TEST).
Secondly, the APACHE service must be set-up to take this user into account. If no user is specified, APACHE uses an anonymous user and this is where the problem/error message is coming from. One must go in control panel->administrative tools->services. One will see the list of services and must look for APACHE with Apache/2.X.X in the description. (For Wampserver, it will be called wampapache, and so on!) Right click on that and pop up the properties screen. In the tab LOG ON, there are 2 options: local system account and "this account" which will be a user specified account. This is where one must specify the USER_TEST and PASS_TEST.
Following these steps worked perfectly for me but if either the folder privileges or apache log on user is disabled, then I get the initial aforementioned error message.
Anyways, I hope this can help out someone!
Cheers!
Marc
--------------------------------------
php官方下面的User Contributed Notes还真不少,,,
试验一下,成功了回来结贴,
谢谢大家!