Jump to content

Archived

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

dhrubajyoti

Connection to a network Drive Using PHP

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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Why don't you setup another webserver on the desired network and access it that way? It just seems easiest to me that way

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites


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

Share this post


Link to post
Share on other sites

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"

Share this post


Link to post
Share on other sites

×
×
  • 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.