简体   繁体   中英

Access network folder using PHP

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) 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM