如何从网络Web服务器在网络客户端上创建文件

时间:2022-03-21 00:47:04

I have a webserver set up on a business network. I am using php to create a file and I want to write it to a local client shared folder also on the network. When I ping from the client I get a response from the webserver. When I ping from the webserver I get a response from the client. Here's my code. I am getting a permissions error. Any ideas what could cause that? Is the path correct? How do I formulate the path?

我在商业网络上设置了一个网络服务器。我正在使用php创建一个文件,我想将它写入网络上的本地客户端共享文件夹。当我从客户端ping我时,我收到了来自网络服务器的回复。当我从网络服务器ping时,我得到了客户的回复。这是我的代码。我收到权限错误。什么可能导致这种想法?路径是否正确?我如何制定路径?

    $fileName = "\\\\7PD01-2012.payday.local\\PTBurnJobs\\file.txt";
    var_dump($fileName);
    if (($myfile = fopen($fileName, "w+")) === false) { //open the file
           //if unable to open throw exception
           throw new RuntimeException("Could Not Open File Location.");
    }
    foreach($arr as $line){
           fwrite($myfile, $line . PHP_EOL);

    }
    fclose($myfile);

Would it be more prudent to create the file on the webserver and then transfer it to the client? How would I do that?

在网络服务器上创建文件然后将其传输到客户端会更谨慎吗?我该怎么办?

1 个解决方案

#1


1  

If you are getting a permissions error, then you will need to check that the user your php script/webserver is running under has write permissions in the client folder.

如果您收到权限错误,那么您需要检查您的php脚本/网络服务器运行的用户是否在客户端文件夹中具有写入权限。

A question for you: How do you know you are getting a permissions error? The code above does not check why something failed, only that it failed.

一个问题:你怎么知道你得到权限错误?上面的代码不会检查失败的原因,只会失败。

If you are getting a permissions error, then it sounds like a successful connection is being made, and you're at least attempting to transfer the file successfully, only getting blocked by your ACL layer.

如果您收到权限错误,那么听起来好像正在建立连接,并且您至少尝试成功传输文件,只是被ACL层阻止。

#1


1  

If you are getting a permissions error, then you will need to check that the user your php script/webserver is running under has write permissions in the client folder.

如果您收到权限错误,那么您需要检查您的php脚本/网络服务器运行的用户是否在客户端文件夹中具有写入权限。

A question for you: How do you know you are getting a permissions error? The code above does not check why something failed, only that it failed.

一个问题:你怎么知道你得到权限错误?上面的代码不会检查失败的原因,只会失败。

If you are getting a permissions error, then it sounds like a successful connection is being made, and you're at least attempting to transfer the file successfully, only getting blocked by your ACL layer.

如果您收到权限错误,那么听起来好像正在建立连接,并且您至少尝试成功传输文件,只是被ACL层阻止。