Reputation: 24766
I'm trying to access a network folder using PHP in windows environment. I have install xampp. here is my code.
$master_path = "\\\\mydir.abc.com\\enu\\px64";
$dh = opendir($master_path);
echo "<pre>\n";
var_dump($dh, error_get_last());
echo "\n</pre>";
The folder I'm trying to access is restricted and only can access using my user account. That is the same account I have log in. But it gives me the error The user name or password is incorrect. (code: 1326)
.
Is there anyway to specify the username and password while accessing network folders. My code works fine with not restricted folders.
Upvotes: 0
Views: 3329
Reputation: 24766
Actually I needed to list the folders in a restricted folder in a remote storage.
Here is finally how I did it. Hope may be helpful to others.
private function map_path($path, $domain,$username,$password )
{
//delete all current mapping
exec("net use * /delete /y");
//create a new mapping to local K: drive
exec('net use k: '.$path.' /user:'.$domain.'\\'.$username.' '.$password.' /persistent:no');
}
public print_dir_list(){}
map_path(str_replace("/","\\",dirname($master_path)),"companey_ds","username","password");
//get the list of folders in local K: drive
exec('dir k:', $output, $ret);
//iterate trough the list and print
foreach($output as $str)
{
echo $str;
}
}
Upvotes: 1