Adding updater for new pf_memory field
[lhc/web/wiklou.git] / maintenance / importImages.inc.php
1 <?php
2
3 /**
4 * Support functions for the importImages script
5 *
6 * @addtogroup Maintenance
7 * @author Rob Church <robchur@gmail.com>
8 */
9
10 /**
11 * Search a directory for files with one of a set of extensions
12 *
13 * @param $dir Path to directory to search
14 * @param $exts Array of extensions to search for
15 * @return mixed Array of filenames on success, or false on failure
16 */
17 function findFiles( $dir, $exts ) {
18 if( is_dir( $dir ) ) {
19 if( $dhl = opendir( $dir ) ) {
20 while( ( $file = readdir( $dhl ) ) !== false ) {
21 if( is_file( $dir . '/' . $file ) ) {
22 list( /* $name */, $ext ) = splitFilename( $dir . '/' . $file );
23 if( array_search( strtolower( $ext ), $exts ) !== false )
24 $files[] = $dir . '/' . $file;
25 }
26 }
27 return $files;
28 } else {
29 return false;
30 }
31 } else {
32 return false;
33 }
34 }
35
36 /**
37 * Split a filename into filename and extension
38 *
39 * @param $filename Filename
40 * @return array
41 */
42 function splitFilename( $filename ) {
43 $parts = explode( '.', $filename );
44 $ext = $parts[ count( $parts ) - 1 ];
45 unset( $parts[ count( $parts ) - 1 ] );
46 $fname = implode( '.', $parts );
47 return array( $fname, $ext );
48 }