php - 我正在尝试使用 php 从 Windows 连接到 Linux 上的 Samba 共享文件夹

标签 php linux windows samba

我在 Windows 7 上有 php,我正在尝试连接到 Linux 上的 Samba 共享文件夹,但没有成功。

我正在使用这段代码:

// Map the drive
system('net use Y: "\\\\linuxIPaddress\Shared_folder password /user:username /persistent:no>nul 2>&1');
// Open the directory
$dir = "Y:/TMP";
if (is_dir($dir)) {
if (opendir($dir)) {
    print "able to access directory tree.";
}
} else {
print "not access tree.";
}

最佳答案

我找到了使用此代码连接的解决方案

$sharename = '\\\\LinuxIPAddress\Shared_folder';
$username = 'username';
$password = 'password';
$letter = 'Z:';    

if (!is_dir($letter . "/TMP")) {
    $WshNetwork = new COM("WScript.Network");
    $WshNetwork->MapNetworkDrive($letter, $sharename, FALSE, $username, $password);
}

工作完美

关于php - 我正在尝试使用 php 从 Windows 连接到 Linux 上的 Samba 共享文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17415530/

相关文章:

php - CSS Div % 宽度问题

linux - 使用 MSBuild 进行远程 Linux 编译

windows - 在 windows 中使用命令行提取 .tar.gz

php - Codeigniter 2.1,MySQL - 两个左连接

php - 在两个表中搜索并使用 PDO 合并结果

php - 在从数据库获取设置的函数上,我遇到了错误

linux - 如何创建最近 30 天文件的 tar

linux - 如何在单行pssh中运行多个命令?

windows - 解压 "wmz"文件

windows - 创建流程时是否存在系统事件?