如何使用 php 中的凭据访问网络驱动器文件夹?

How to access network drive folder using credentials in php?

我正在编写如下所示的 php 代码,其中我想使用 php 中的凭据访问网络驱动器文件夹(音乐)。凭据 正在设置,因为我只想将完全访问权限授予特定用户。

$src_dir = '\\INVEST-OP-001\test\music'; // 行#A

音乐文件夹的完整permission/access已提供给以下凭据:

username : 'mickeymouse'
password : 'helloworld'

问题陈述:

我想知道我应该对第#A 行的 php 代码进行哪些更改,以便我可以使用 php 中的凭据访问音乐文件夹。

这对我有用:

<?php

$user = 'mickeymouse';
$password = 'helloworld';

exec('net use "\\INVEST-OP-001\test\music" /user:"'.$user.'" "'.$password.'" /persistent:no');
$files = scandir('\\INVEST-OP-001\test\music');
echo '<pre>';
print_r($files);

exec('net use "\\INVEST-OP-001\test\music" /delete /yes');