简体   繁体   English

如何使用PHP在另一台PC上写入文件txt?

[英]How can I write a file txt in another PC by using PHP?

I'm trying to write a file text from PHP file and save it in another PC in the same network, so that is what I write : 我正在尝试从PHP文件写入文件文本,并将其保存在同一网络中的另一台PC中,这就是我写的内容:

$myfile = fopen("192.168.100.18/file.txt", "w") or die("Error!");

so I got an error message, what should I do ? 所以我收到一条错误消息,该怎么办?

** note: I'm using Linux for both PCs **注意:我在两台PC上都使用Linux

To achieve this you need to call a script on the other pc, so the URL would be like this: 为此,您需要在另一台PC上调用脚本,因此URL如下所示:

PHP on the request side: PHP在请求端:

<?php

file_get_contents("192.168.100.18/save-file.php");

?>

PHP on the recipient side: 收件人端的PHP:

Create a file at the root called save-file.php and set the contents of the file to the following script: 在根目录下创建一个名为save-file.php的文件,并将文件内容设置为以下脚本:

<?php

file_put_contents("file.txt", "some string");

?>

This way, every time you will load the script on the first pc it will request the save-file.php script on the other pc which in turn will save the file. 这样,每次将脚本加载到第一台PC上时,它将在另一台PC上请求save-file.php脚本,而该脚本又将保存文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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