note 29128 added to function.opendir
| From: | tvorobjo at colby dot edu | Date: | Tue, 04 Feb 2003 00:13:23 +0000 |
| Subject: | note 29128 added to function.opendir | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-43347@lists.php.net to get a copy of this message | ||
Here is a way I use to get all the filenames into an array:
$mydir = mydir //the directory name
$output_file = fopen($data_file, "w");
$begin = "<?
\$files_name = array(";
fwrite($output_file, $begin);
$output_file = fopen($data_file, "w");
if ($handle = opendir('./$mydir/')) {
while (false !== ($filename = readdir($handle))) {
if ($file != "." && $filename != "..") { //&&
!is_dir($filename) can be added
$element = "\"$filename\",";
fwrite($output_file, $element);
}
}
closedir($handle);
}
fwrite($output_file,"\"\");\r\n");
fwrite($output_file, "?>");
fclose($output_file);
chmod($output_file, 0777); //to preview
echo "the list has been succesfully created";
-----------------------------------------------
anyone knows how to search throught subdirectories of $mydir???
--
http://www.php.net/manual/en/function.opendir.php
http://master.php.net/manage/user-notes.php?action=edit+29128
http://master.php.net/manage/user-notes.php?action=delete+29128
http://master.php.net/manage/user-notes.php?action=reject+29128