Using PHP's fopen in windows on a network drive

廉价感情. 提交于 2019-12-13 21:36:57

问题


I have the following code:

$file_name = "1234";
$filename = "L:\\videoette_converter\\batch_files\\".$file_name.'.bat';
if (!$handle = fopen($filename, 'a')) {
     echo "Cannot open file ($filename)";
     exit;
}

I get the following error from that code:

Warning: fopen(L:\videoette_converter\batch_files\1234.bat) [function.fopen]: failed to open stream: No such file or directory in C:\wamp\www\videoette_converter\index.php on line 47

and the debug line from my php

Cannot open file (L:\videoette_converter\batch_files\1234.bat)

However the folder L:\videoette_converter\batch_files does exist as a mapped drive, and I have given "Everyone" full permissions. What could be the problem?


回答1:


Are you sure there's no domain controller in the way?

When the Windows machine that serves the files is in an Active Directory domain:

1) The machine that runs the WAMP must be in the same domain.

2) The account used to run the Apache service on your WAMP machine must have at least read rights on the share you want to access. Instead of running the Apache service as "Local System" or "wampapache" you should specify your domain user account. (P.S.: I like XAMPP over Wamp for this kind of development, but that's probably just a personal preference)

Also I'm guessing id'd be better if you used a UNC path instead of a drive letter. It always worked for me that way. You don't need to use escaped backslashes, you can replace them with single forward ones:

//yourwinserver/sharename/path/to/file.bat



来源:https://stackoverflow.com/questions/9078542/using-phps-fopen-in-windows-on-a-network-drive

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!