Jump to content


Reading files from a directory


2 replies to this topic

#1 derek.sullivan

    Jedi In Training

  • Members
  • PipPip
  • 341 posts
  • Gender:Male
  • Location:Georgia
  • Interests:preaching, programming, music, friends, outdoors, moves, books

Posted 07 July 2007 - 11:15 AM

How would I read files from a certain directory? I've looked all over and I couldn't find anything.

#2 Braunson

    Young Padawan

  • Members
  • Pip
  • 237 posts
  • Gender:Male
  • Location:Ontario, Canada

Posted 07 July 2007 - 12:40 PM

PHP Function read_dir
ALSO See your directory functions here!

Example to display files from a directory:
<?php

if ($handle = opendir('/path/to/files')) {
	echo "Directory handle: $handle\n";
	echo "Files:\n";

	/* This is the correct way to loop over the directory. */
	while (false !== ($file = readdir($handle))) {
		echo "$file\n";
	}

	closedir($handle);
}
?>

Edited by Braunson, 07 July 2007 - 12:42 PM.


#3 high6

    Young Padawan

  • Members
  • Pip
  • 57 posts

Posted 07 July 2007 - 01:52 PM

View PostBraunson, on Jul 7 2007, 01:40 PM, said:

PHP Function read_dir
ALSO See your directory functions here!

Example to display files from a directory:
<?php

if ($handle = opendir('/path/to/files')) {
	echo "Directory handle: $handle\n";
	echo "Files:\n";

	/* This is the correct way to loop over the directory. */
	while (false !== ($file = readdir($handle))) {
		echo "$file\n";
	}

	closedir($handle);
}
?>


Newest php has a function called, scandir. Which is what you have above.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users