我们有一堆 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 需要对共享进行身份验证,即使它是公开的,使用 fopen
或 opendir
也不会这样做。
关于php - Linux Box 使用 PHP 将文件写入 Windows Server Web Share,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11971069/