Using PHP's fopen in windows on a network driv

2019-09-06 14:38发布

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条回答
兄弟一词,经得起流年.
2楼-- · 2019-09-06 15:15

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

查看更多
登录 后发表回答