Reading Remote Directories from Apache SAPI

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
vmsgman
Forum Newbie
Posts: 2
Joined: Thu Dec 15, 2005 3:46 pm
Location: Salt Lake City

Reading Remote Directories from Apache SAPI

Post by vmsgman »

I have been trying to get a webpage to tell me whether a remote directory exists.
Using UNC paths ... //RemoteServer/Directory

I can use the php.exe to read the directory fine from the command line. But when I run it from the web page with the exec call it fails. I will post the code below. I suspect that this is a perms issue. BUT I have made the directory readable by the SYSTEM user which is what apache runs under I believe. Here is the code sample ... I can run dircmd.php from the command line successfully but when I try to get the webserver to execute it with dirtest.php it fails. :evil:

dirtest.php

Code: Select all

<?php
	$pnl = "Dir1";
	$cst = "Dir2";
	
	exec('php-win.exe dircmd.php '.$pnl.' '.$cst,$out);
	//pclose(popen('start /b dircmd.php '.$pnl.' '.$cst, 'r'));
	//exec('start /b php -v',$out);
	print_r($out);
?>

dircmd.php
<?php
$pnl = $argv[1];
$cst = $argv[2];

if(!isset($argv[1]) || !isset($argv[2])) {
	exit("ERROR need to pass in pnl cust!");
}
	
$pth = "\\\\FileServer1\\DirLevel1\\DirLevel2";
$dir = $pth."\\".$pnl."\\".$cst;

if (is_dir($dir)) {
   $fp = fopen("C:\\Documents and Settings\\user\\Desktop\\dir","w");
   fwrite($fp,"OK");
   fclose($fp);
   $out = "OK";
} else {
   $fp = fopen("C:\\Documents and Settings\\user\\Desktop\\dir","w");
   fwrite($fp,"NOT-OK ".$pnl." ".$cst." ".$dir);
   fclose($fp);
   $out = "NOT-OK";
}

return $out;
?>

Can anyone help. I'm sorry if this is the wrong place, but this seems like a program architecture problem more than a coding issue. Let me know if you feel this post is misplaced.

THX g

Burrito: Please use

Code: Select all

tags when [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting PHP Code In The Forums[/url][/size]
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post by Maugrim_The_Reaper »

You'd get more answers on the PHP Code forum...

Not a clue from me - never needed to do it. But why are you using exec() to call what is essentially another PHP script?
vmsgman
Forum Newbie
Posts: 2
Joined: Thu Dec 15, 2005 3:46 pm
Location: Salt Lake City

Post by vmsgman »

Hey thanks for at least answering. The reason is that I believe that it is for security reasons that this can't be done. I may be way off here but if I execute it on the command line it works fine, if I try and do it through the web server SAPI it won't so I was trying to be clever by using exec() so that it would use the CLI version of php and maybe work, BUT it didn't. If you noticed one of the commented lines was simply php -v because I wanted to see if IT was indeed the command line version that was being executed and was.

!!!!! I am moving this post to the code forum if anyone has some insight here !!!!!!

THX g
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

Moved to PHP - Code
Post Reply