Click to See Complete Forum and Search --> : Current Directory...


Anon
07-31-2000, 12:41 PM
I tried this with PHP on Linux, and it worked.

<?
$current_dir = exec("cd") ;
echo "The current directory is [$current_dir] " ;

?>
On Windows, all this returns is:

The current directory is [

Note the lack of the closing bracket...
There isn't any suspicious in the Apache log files.
I'm wondering why this won't work.

I'm using PHP 3, and Apache 1.3.12 on a windows 98 box.

This is going to be a file management piece, eventually.

Anon
07-31-2000, 01:24 PM
It turns out that the results are being displayed on the Apache console.
It's just not getting stored into the variable.

Being that, I tried:

The current directory is

<?
system("cd") ;
?>

And that didn't return anything to the browser, but it displayed the results to the console screen.

-Help?

Anon
07-31-2000, 01:34 PM
This should work on both unix and NT

$basename = basename($PATH_TRANSLATED);
$current_dir = ereg_replace("$basename", "", $PATH_TRANSLATED);
print $current_dir;

Anon
07-31-2000, 02:05 PM
It worked, thank you. Could you tell me why the original snippet i posted didn't work?

Thanks again.
-Lysa

Anon
08-01-2000, 01:21 AM
I am not really sure why it doesn't work. But I have a feeling that the way php interacts with the server may vary between unix and NT.