Quote:
Originally Posted by Peuplarchie
Good day to you all,
I have a script here that read a directory and return the files to an array.
I need that array to also contain the last modified date, width, height and size of the files, they are images.
here's what I'm working with :
PHP Code:
function dircont($imgdir) { $dir_array = array(); if (false !== ($dir = opendir($imgdir))) { while (false !== ($file = readdir($dir))) { if ($file != '.' && $file != '..') { $dir_array[] = $file; } } return $dir_array; } else { return false; } }
// To print.. // $path = "/home/helpelf/helpelf-www/"; echo "<pre>"; print_r(dircont($imgdir)); echo "</pre>";
Thanks !
Take good care !
|
You need to allow the array to write inside the while loop, so that way, it writes the filemtime, etc into that array every file in the loop, same goes for the rest of it.
What I mean for that is
PHP Code:
while ( etc etc ) {
$contentArray[$file]['modifiedTime'] = filemtime($file);
// This would mean that we make a new key with the filename, and then make an array inside the filename element, ( multidemnsional array ), and inside the new array inside the file's element, it adds the modified time. you can do the same for width, height, etc.
}
Maybe you need to understand a little bit more about while loops?
Also, you don't need to put else { return false; } in there, you can only have a single thing returning from a function.
By the way, you don't need if ( $file != "." & !=".." ), you can do this aswell, if ($file==".") continue, which takes out all the periods in there, this can only work in a loop.
Also, your files wont be listed, as since you don't have the return $dir_array inside the while loop, plus you need to put it in the if statement if your going to do it with the != operand.