Re: creating a text file
| From: | Burhan Khalid | Date: | Thu, 10 Apr 2003 15:14:54 +0000 |
| Subject: | Re: creating a text file | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-143354@lists.php.net to get a copy of this message | ||
On Thu, 2003-04-10 at 09:52, Tyler Durdin wrote:
> Is there a way to make php create a text file that lists contents of a
> directory? This is what I use from shell:
> csh -c "ls *jpg > list.photos"
>
> I have a photo gallery that reads the images in a directory from a text
> file. I would like to eliminate the manual creation of that file. If there's
> a better way to do it, maybe firing it into a db instead of a textfile or
> having php read the contents of the directory without creating a text file,
> please let me know. I appreciate the help.
>
If all you want is a text file that lists the contents of a directory,
then this should do it (untested) :
function dirListing ($dirname, $filename) {
$handle=opendir($dirname);
if (!$handle) { return false; }
if (! ($fp = fopen($filename, "w") ) ) { return false; }
while ($file = readdir($handle))
{
if($file=='.'||$file=='..')
continue;
else
fputs($fp,$file."\n");
}
closedir($handle);
fclose($fp);
return true;
}
--
Burhan Khalid
phplist[at]meidomus[dot]com
Please add a reply-to: header
in your messages that points
to the mailing list address
so that all mail is properly
archived and viewed.