Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is there a function to read the contents of a directory?

Status
Not open for further replies.

tristero

Programmer
Jan 24, 2003
95
US
Is there a function to read the contents of a directory into a string or array? thanks.
 
Try this:
Code:
<?
$dircontent = `ls -m /images/etc`; // backtick
$files = $explode(&quot;, &quot;, $dircontent);
?>
this gives you an array of files in /images/etc. I'f you're familiar with ls you can provide other options. Of course this only works on UNIX servers, not on windows or other incompatible ones...
 
i've tried everything from readdir to scandir (turns out my server only supports php4 and this is a php5 function)...

i keep getting &quot;openbase_dir restriction is in effect&quot;

does this mean that i can't use these functions?
 
So i can't use directory functions on subdirectories?

this is not my machine, is there no work around?

 
how do i find out which directory is specified by the open_basedir?

i believe i am trying to read directories that are within these boudaries...

i can't even get opendir() to work...

Code:
<?
if ($handle = opendir('/images/')) {


   closedir($handle); 
}
?>
 
If you invoke phpinfo(), you should be able to see what PHP's settings are.

If the &quot;images&quot; directory is a subdirectory of where your script resides, you want to issue:
opendir('images')
not
opendir('/images')

PHP's filesystem and directory functions operate on filesystem paths, not document root paths. So the first invocation above is trying to open the directory &quot;/images&quot;, where the second is trying to open &quot;/path/to/your/script/images&quot;.

Want the best answers? Ask the best questions: TANSTAAFL!!
 
Ahhhahahahahaa

that was it!

/

thank you!!!

it always seems to come down to a / or a ;

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top