doubi7496
2013-07-02 00:10
采纳率: 0%
浏览 76
已采纳

我正在尝试使用php从Linux连接到Linux上的Samba Shared文件夹

I have php on Windows 7 and I'm trying to connect to Samba Shared folder on Linux but no success.

I'm using this code:

// 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.";
}

图片转代码服务由CSDN问答提供 功能建议

我在Windows 7上安装了php,而我正在尝试连接Linux上的Samba Shared文件夹,但没有成功。< / p>

我正在使用此代码:

  //映射驱动器
system('net use Y:“\\\\ linuxIPaddress  \ Shared_folder密码/用户:username / persistent:no&gt; nul 2&gt;&amp; 1'); 
 //打开目录
 $ dir =“Y:/ TMP”; 
if(is_dir($ dir)){  
if(opendir($ dir)){
 print“能够访问目录树。”; 
} 
} else {
print“not access tree。”; 
} 
   
 
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • doucai7294 2013-07-02 13:05
    已采纳

    i found solution for connection using this code

    $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);
    }
    

    and is working perfect

    点赞 打赏 评论
  • dongtanzhu5417 2017-05-15 14:53

    This is more of a comment, but I don't have enough reputation to comment yet, so: @DanielMiovski 's solution did work for me as well. Once I mapped it in the script I was able to manipulate the files I wanted to. However, I ran into a problem. On Windows 10, once the script ended the drive was not deleted from my network drives. I could not manually disconnect it via explorer nor the command prompt because: "The network connection does not exist." I searched for many solutions to this on the internet and finally got it to go away, but it took way to much effort for something that simple. I still wanted to use this code in my script, because it was the only smb solution for php that actually worked for me. I found a solution to both problem. Use @Daniel Miovski 's script above, but at the end, add this line:

    system('net use Z: /delete /y');
    

    This deletes the network drive as soon as the script is done manipulating it. I have not had any troubles of this kind since.

    Just thought that I would post this in case anyone else was running into this same problem.

    点赞 打赏 评论

相关推荐 更多相似问题