note 82539 added to function.glob

From: Date: Tue, 15 Apr 2008 19:08:02 +0000
Subject: note 82539 added to function.glob
Groups: php.notes 
Request: Send a blank email to php-notes+get-138337@lists.php.net to get a copy of this message
Here is a function that returns specific files in an array, with all of the details. Includes some basic garbage checking. Variables $source_folder // the location of your files $ext // file extension you want to limit to (i.e.: *.txt) $sec // if you only want files that are at least so old. The function function glob_files($source_folder, $ext, $sec, $limit){ if( !is_dir( $source_folder ) ) { die ( "Invalid directory.\n\n" ); } $FILES = glob($source_folder."\*.".$ext); $set_limit = 0; foreach($FILES as $key => $file) { if( $set_limit == $limit ) break; if( filemtime( $file ) > $sec ){ $FILE_LIST[$key]['path'] = substr( $file, 0, ( strrpos( $file, "\\" ) +1 ) ); $FILE_LIST[$key]['name'] = substr( $file, ( strrpos( $file, "\\" ) +1 ) ); $FILE_LIST[$key]['size'] = filesize( $file ); $FILE_LIST[$key]['date'] = date('Y-m-d G:i:s', filemtime( $file ) ); $set_limit++; } } if(!empty($FILE_LIST)){ return $FILE_LIST; } else { die( "No files found!\n\n" ); } } So.... $source_folder = "c:\temp\my_videos"; $ext = "flv"; // flash video files $sec = "7200"; // files older than 2 hours $limit = 2; print_r(glob_files($source_folder, $ext, $sec, $limit)); Would return: Array ( [0] => Array ( [path] => c:\temp\my_videos\ [name] => fluffy_bunnies.flv [size] => 21160480 [date] => 2007-10-30 16:48:05 ) [1] => Array ( [path] => c:\temp\my_videos\ [name] => synergymx.com.flv [size] => 14522744 [date] => 2007-10-25 15:34:45 ) ---- Server IP: 209.41.74.194 Probable Submitter: 64.60.194.194 ---- Manual Page -- http://www.php.net/manual/en/function.glob.php Edit -- https://master.php.net/note/edit/82539 Del: integrated -- https://master.php.net/note/delete/82539/integrated Del: useless -- https://master.php.net/note/delete/82539/useless Del: bad code -- https://master.php.net/note/delete/82539/bad+code Del: spam -- https://master.php.net/note/delete/82539/spam Del: non-english -- https://master.php.net/note/delete/82539/non-english Del: in docs -- https://master.php.net/note/delete/82539/in+docs Del: other reasons-- https://master.php.net/note/delete/82539 Reject -- https://master.php.net/note/reject/82539 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#138337) next »