PDA

View Full Version : Directory/File count with shell_exec


Dalsor
08-31-2002, 05:04 PM
Greetings,

I'm trying to get a quick count of files within a static directory using this tiny snip. The snip always returns 0 for some reason. Not quite sure why. The command, if issued in the shell itself, retuns the actual file count as intended, just not if used in the script. I've tried varying the path statement itself with no success. This is the latest incarnation of the failed attempts. Any advice?


<?php
$dir = shell_exec("ls -la '/path/to/my/files/*'|wc -l|sed 's/^ *//;'");
?>
Players <?php echo($dir); ?><br>

firepages
09-01-2002, 04:11 AM
have you tried a simpler command line (just to see if anything is working... (I like exec() BTW))

exec('ls -al',$yaks);foreach($yaks as $var){echo $var;}

Dalsor
09-01-2002, 01:53 PM
Thanks for the reply, Fire.

I've tried a few different means now. :) It seems to boil down to PHP not being able to access anything outside the public_html, which may be due to some recent security modifications the server admin made - or maybe not. Gonna cheat and output a txt file with the count in it when the base application boots, then just include it. Not as accurate as a real-time count, but it will be pretty close.

Thanks for the help!