Jump to content

Connection to a network Drive Using PHP


dhrubajyoti

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/194629-connection-to-a-network-drive-using-php/
Share on other sites

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


// 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

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"

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.