Accessing a shared network directory on a Ip using php

I had tired a lot to access a shared network directory on LAN but i was not successful please help me how could i access the shared directory on a ip address using php. I am running windows xp and WAMP( Apache, MYSQL , PHP 5.26 ) server on it.

Here is the code i have tried and please do not correct the code give a solution to a problem this script works fine for the directories shared on my Ip address but not works for other ip address so please tell me what wrong.

Is there any other approach for access the shared files on a network.
Please Do not tell me to mount the network directories in windows XP and then try to access them in php. :banghead: i know this too but i need an other way.

Here is my code for accessing the directories( which wont work ) .


<pre><?php

	$ip = '192.168.XX.XX';
	$host = gethostbyaddr( $ip );
	if ( $ip == $host )
		die( 'Unable to resolve hostname from ip '.$ip );

	$path = '//'.$host.'/directory';
	
	if ( !is_dir($path) )
		die( $path. ' is not a directory' );   //here it gives me error :: is not a directory even the path is correct.

	$dir = opendir($path);
	if ( $dir == FALSE )
		die( 'Cannot read '.$path );
		
	while (($file = readdir($dir)) !== FALSE)
		echo "filename: $file : filetype: ".filetype( $path.$file)."\
";
		
	closedir( $dir );


?></pre>

Is Apache restricting the access.

What does the failure look like? Does it bring up one of your error messages?

At this point it show error


if ( !is_dir($path) )
		die( $path. ' is not a directory' );

Here is the example path
\\192.168.11.51\Movies
Note that the above path can be accessed in windows XP by going to
start>Run…>\\192.168.11.51\Movies

If i use above path in my code like


<pre><?php
	$ip = '192.168.11.51';
	$host = gethostbyaddr( $ip );
	if ( $ip == $host )
		die( 'Unable to resolve hostname from ip '.$ip );

	$path = '//'.$host.'/Movies/';
	
	if ( !is_dir($path) )
		die( $path. ' is not a directory' );

	$dir = opendir($path);
	if ( $dir == FALSE )
		die( 'Cannot read '.$path );
		
	while (($file = readdir($dir)) !== FALSE)
		echo "filename: $file : filetype: ".filetype( $path.$file)."\
";
		
	closedir( $dir );
?></pre>

it give me this error.
//PC/Movies/ is not a directory
or
//PC/Movies is not a directory

In both cases either i place / after movies or not.

What happens if you use Windows backslash style path separators in your code then? (you may need to escape each backslash with a backslash)

http://php.net/manual/en/wrappers.php

well have used wrappers and used windows backslash in my code it gives me the following error

\\PC\Movies is not a directory

here what i have changed in the code


$path = '\\\\\\\\'.$host.'\\Movies';
or
$path = '\\\\\\\\'.$host.'\\\\Movies';

Same error nothing changes

What happens if you use the IP instead of the host name for the $path variable?

$path = '\\\\\\\\192.168.11.51\\\\Movies';

same error


\\\\192.168.11.51\\Movies is not a directory

Sorry then, I was hoping it might be a simple PHP code tweak. I’m not a Windows guy so hopefully someone who is can chime in.

Well i have posted it on other forums too no one has replied me yet only the things they have helped was correcting the same things as you have.

Come on people there are other ways to build LAN search engine in php. Please some one guide how could i access the shared file on the network using any other programing language or guide me how should i build a LAN search engine. I have heard that php can also be used as desktop development language( or any any other language ) may be from there i can build an application that can read the shared network directories and stores the result in databases and using php web i can interact with database and search the required results.

Any other ideas how should i access the shared network directories using programming languages.
Any method which are slow or fast please tell me.

I assume you have mounted the network drive on the XP machine and it worked fine?

First of all PHP can open networked drives.

Also, the access to the drive needs to be previously authenticated, so the authentication process need not be done by PHP, which cannot do it. Meaning that it will only work if you opened the network drive manually first using explorer and supplied to proper credentials (login & password), which the system then used automatically for all future connections.

If no authentication has been done such as you already mounting the drive manually then it will default to the anonymous user for apache. You could setup an FTP service or SSH service on the other XP machine and pull data via a socket.

You could also take a look at this thread of a person with the similar problem and how they managed to solve it. http://us.php.net/manual/en/function.opendir.php#79685

Also make sure that the share is set so everyone can view it and no authentication is needed. Hope this provides a bit of help. :cool:

Sorry for my bad post i can access the mounted network drives. Future more i am also thinking its Apache is restricting the access.

http://us.php.net/manual/en/function.opendir.php#79685

I have read the this post since there is no password in the shared network directories it depend on other people weather they give password for there sharing or not.
If this i Apache problem should i go for IIS

You could try IIS and see what happens. If the same thing happens on IIS then more than likely it’s not an HTTP server issue but a limitation of PHP itself.

Dudes using php with IIS 6.0 the error is same no change
here is the error


//PC/Movies/ is not a directory
or
//PC/Movies is not a directory