php - Linux Box 使用 PHP 将文件写入 Windows Server Web Share

标签 php windows linux fwrite

我们有一堆 linuix 和 windows 服务器。

在我的 Windows 桌面上,我可以看到所有共享。

使用 PHP,我尝试使用 UNC 路径将文件写入 Windows 共享上的目录。

//ServerShare/directory/file.txt

使用 fwrite 表示它已成功写入文件,但该文件从不存在于服务器上。

使用 opendir 函数说目录不可访问。

这是非常简单的来源。

 $file_name = "\\SERVER2\Share\CPI\data.txt";

if (!$handle = fopen($file_name, 'w')) {
     echo "Cannot open file ($file_name)";
     exit;
}

// Write $somecontent to our opened file.
$somecontent = "this is a test";
if (fwrite($handle, $somecontent) === FALSE) {
    echo "Cannot write to file ($filename)";
    exit;
}

echo "Success, wrote ($somecontent) to file ($file_name)";

fclose($handle);

关于需要设置什么类型的权限让 linux 机器将文件写入 windows 机器有什么想法吗?

最佳答案

您应该将文件共享挂载到本地目录:

mount -f smbfs //user@server2/Share/CPI/Data.txt /media/share

然后从您的 PHP 脚本访问 /media/share/Share/CPI/Data.txt

PHP 需要对共享进行身份验证,即使它是公开的,使用 fopenopendir 也不会这样做。

关于php - Linux Box 使用 PHP 将文件写入 Windows Server Web Share,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11971069/

相关文章:

PHP strtotime 将 false 保存为 MySQL 负整数

php - 如何在 PHP 中为每次出现的字符串拆分数组

php - 我需要理解类(class)

php - mySQL COUNT 与两个表上的 JOIN

Apache下的PHP exec()运行脚本时返回null和255

linux - Magento 模块适用于 OS X 而不是 Linux

c - 编写 Windows 端口监视器基础知识

windows - cmd - 是否可以临时将可用的驱动器号分配给本地路径?

linux - ELF 可执行文件的起点?

regex - 如何更改文本文件 linux/unix 中的日期格式