All of the entries that got the right idea are posted below.
the winning entry was submitted by Tino (the moderator) and is shown below.
<?php
header('Content-Type: text/plain');
function new_scandir($dir) {
$files = array();
$x = 0;
foreach ( glob("{$dir}*") as $file ) {
$files[$x] = array();
// use of stat function to minimize amount of function calls like fileowner()
// using this i could've added a lot more to the array but that would've gotten ridiculous
// i mean, device number? pointless :p
$stats = stat($file);
$files[$x]['path'] = $file;
$files[$x]['name'] = basename($file);
$files[$x]['in_dir'] = dirname($file);
$files[$x]['type'] = filetype($file);
if ( function_exists('finfo_file') ) {
if ( phpversion() >= '5.3.0' ) {
$info = finfo_open(FILEINFO_MIME_TYPE);
$files[$x]['mime_type'] = finfo_file($info, $file);
} else {
$info = finfo_open(FILEINFO_MIME);
$files[$x]['mime_type'] = finfo_file($info, $file);
}
finfo_close($info);
} else {
$files[$x]['mime_type'] = mime_content_type($file);
}
// doesn't work on windows
if ( function_exists('posix_getgrgid') ) {
$info = posix_getgrgid(filegroup($file));
$files[$x]['group'] = $info['name'];
} else {
$files[$x]['group_id'] = filegroup($file);
}
// doesn't work on windows
if ( function_exists('posix_getpwuid') ) {
$info = posix_getpwuid(fileowner($file));
$files[$x]['owner'] = $info['name'];
} else {
$files[$x]['owner_id'] = $stats['uid'];
}
$files[$x]['created'] = date('d/m/Y h:i:s', $stats['ctime']);
$files[$x]['last_mod'] = date('d/m/Y h:i:s', $stats['mtime']);
if ( is_file($file) ) {
$files[$x]['size'] = (int) ($stats['size'] / 1024) . 'kB';
}
if ( is_dir($file) ) {
$files[$x]['dir'] = new_scandir($file.'/');
}
$x++;
}
return $files;
}
print_r(new_scandir('./'));
?>
Task:- To create a function similar to scandir()
- As much information on each file and folder should be found as you can work out how to do
- The winner will be the person who finds the most things.
Rules:
- You can use any PHP function, but no external programs.
- No cheating.
Prize:
- Any game / codecanyon item under £10, see previous announcement for more info.
