Page 1 of 1

Reading Remote Directories from Apache SAPI

Posted: Thu Dec 15, 2005 4:06 pm
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]

Posted: Fri Dec 16, 2005 6:20 am
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?

Posted: Fri Dec 16, 2005 12:57 pm
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

Posted: Fri Dec 16, 2005 1:08 pm
by hawleyjr
Moved to PHP - Code