dhrubajyoti Posted March 9, 2010 Share Posted March 9, 2010 Hi, I want to connect to a computer in my network, where the computer is password protected. So what we normally do is, type \\<ip or computer name>. Then when it prompts for username and pass, we provide it in the pop-up window. So, when we do a opendir('directory name'), it opens normally. but what to do if this ddirectory has some pass. Please help. This is really urgent and I am stuck up. My Code is <?php function open_dir ($dir_name) { if ($handle = opendir ($dir_name)) { while (($file = readdir($handle)) != false) { if ($file != '.' && $file != '..') if (filetype($dir_name.'/'.$file)== 'dir') { open_dir ($dir_name.'/'.$file); } else { echo $file." "; echo "-------------"; insert_into_database ($dir_name, $file); } } closedir($handle); } } open_dir ("\\\\192.168.1.2\folder"); ?> What to do if "\\\\192.168.1.2\" computer in the network has password Quote Link to comment https://forums.phpfreaks.com/topic/194629-connection-to-a-network-drive-using-php/ Share on other sites More sharing options...
Zane Posted March 9, 2010 Share Posted March 9, 2010 You need to map the network drive instead of accessing it like a ..... network share Here's a good post on it (note that it's in the PHP manual... under opendir) http://us.php.net/manual/en/function.opendir.php#90373 Quote Link to comment https://forums.phpfreaks.com/topic/194629-connection-to-a-network-drive-using-php/#findComment-1023614 Share on other sites More sharing options...
dhrubajyoti Posted March 9, 2010 Author Share Posted March 9, 2010 Hi, Thanks a lot for your reply. I have seen this tutorial on php.net. But could not build my code accordingly. So, I am supplying with the credentials. If possible, PLZ help me write the code IP to be connected : 192.168.1.4 Folder to be accessed : \\19.168.1.4\folder1\folder_test Username of 192.168.1.3 : user Password of 192.168.1.3 : pass I just want to access folder_test directory. Sir, plz help Quote Link to comment https://forums.phpfreaks.com/topic/194629-connection-to-a-network-drive-using-php/#findComment-1023621 Share on other sites More sharing options...
Zane Posted March 9, 2010 Share Posted March 9, 2010 Why don't you setup another webserver on the desired network and access it that way? It just seems easiest to me that way Quote Link to comment https://forums.phpfreaks.com/topic/194629-connection-to-a-network-drive-using-php/#findComment-1023622 Share on other sites More sharing options...
dhrubajyoti Posted March 9, 2010 Author Share Posted March 9, 2010 Actually Its in my office and we are not allowed to do any modification. All I have is--a local server installed in my system and the ip of the desired Computer in the network. Quote Link to comment https://forums.phpfreaks.com/topic/194629-connection-to-a-network-drive-using-php/#findComment-1023623 Share on other sites More sharing options...
Zane Posted March 9, 2010 Share Posted March 9, 2010 // Define the parameters for the shell command $location = "\\192.168.1.4\folder1\folder_test"; $user = "USERNAME"; $pass = "PASSWORD"; $letter = "Z"; // Map the drive system("net use ".$letter.": \"".$location."\" ".$pass." /user:".$user." /persistent:no>nul 2>&1"); // Open the directory $dir = $letter . ":"; function open_dir ($dir_name) { if ($handle = opendir ($dir_name)) { while (($file = readdir($handle)) != false) { if ($file != '.' && $file != '..') if (filetype($dir_name.'/'.$file)== 'dir') { open_dir ($dir_name.'/'.$file); } else { echo $file." "; echo "-------------"; insert_into_database ($dir_name, $file); } } closedir($handle); } } ?> that's the best I can come up with Quote Link to comment https://forums.phpfreaks.com/topic/194629-connection-to-a-network-drive-using-php/#findComment-1023629 Share on other sites More sharing options...
dhrubajyoti Posted March 9, 2010 Author Share Posted March 9, 2010 Why are we putting $letter = "Z"; what does this drive stand for....???? Quote Link to comment https://forums.phpfreaks.com/topic/194629-connection-to-a-network-drive-using-php/#findComment-1023708 Share on other sites More sharing options...
dhrubajyoti Posted March 9, 2010 Author Share Posted March 9, 2010 If I type net use Z: \\192.168.1.5\Databases\data\account PASSWORD /user:USERNAME /persistent:no in command prompt and then I try to access Z: thorugh COmmand prompt, it works. But If I try to do the same using PHP, it says "Warning: opendir(Z:) [function.opendir]: failed to open dir: No error in C:\wamp\www\knet\handle.php on line 28" Quote Link to comment https://forums.phpfreaks.com/topic/194629-connection-to-a-network-drive-using-php/#findComment-1023756 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.