View Single Post
Old 11-09-2008, 11:21 PM   #2 (permalink)
Runar
The Contributor
 
Runar's Avatar
 
Join Date: Nov 2008
Location: Norway
Posts: 58
Thanks: 20
Runar is on a distinguished road
Default

I quite recently learned that glob() is the way to do this. The function will find pathnames matching a pattern (according to the manual) and works perfectly as a replacement for opendir() and all those functions.

PHP Code:
<?php

// Turn on error reporting
ini_set'display_errors''yes' );

// Set path to our directory (for easier use)
// Remember the last slash (/)!
$directory_path 'your/folder/';

// Return .png files found in the directory
foreach( glob$directory_path '{ *.file1, *.file2, *.file3 }'GLOB_BRACE ) as $file )
{
    
// Put some file data in variables
    
$name basename$file );
    
$size filesize$file );
    
$file implodefile$file ) );
    
    
// Do your thing, for example add the info to an array
    // or output it directly
    // $files[]  = array( 'name' => $name, 'size' => $size, 'content' => $file );
}
    
?>
Send a message via MSN to Runar
Runar is offline  
Reply With Quote