You Are Here Home > Get The Contents Of a Folder

Get The Contents Of a Folder

One method is to use folder functions such opendir, readdir etc.

Here is a function that returns the contents of a folder in an array:

<?php
           function get_folder_contents($folder) {		
		if(!is_dir($folder)) {
			return array(); /* You might want to do something more useful here */
		}
		$return_array = array();
		if ($dh = opendir($folder)) {
			while (($file = readdir($dh)) !== false) {
				if($file == '.' || $file == '..') continue;
 
				$return_array[] = $folder .$file;
 
			}
			closedir($dh);
		}
		return $return_array;
	}
?>
Get The Contents Of a Folder
Filed under: PHP   Posted by: Hamid

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment