I am new to this forum. I inherited a website 6 months ago with bits of php code on most pages. I have been studying lynda.com, W3C and books and I am beginning to understand more, but at a advanced beginner level. I use Dreamweaver CS4 and have been able to work around any code I don't understand (mostly because it is still working!). Any time it gets in my way, I comment it out and do the same thing with html.
I would like to be able to take some of the more complex code and really understand what it is doing. I can pick out php terms and I understand them quite well, but sometimes putting it all together doesn't make it very clear. I can figure out the general idea of what is happening, but not the specifics. How long does this take someone who is self study to learn?
Right now my specific problem I need help with from this forum is that I have a php code script that basically looks at all the files in a directory, figures out how big they are, assigns them MB, KB etc using php math and then echoes all the file names, along with these file types and sizes (ex: This Is The File Name (PDF 47 KB)) on the page. This much of the php and how it works, I sort of understand.
I cannot understand how the php defines how files are ordered when placed on the page. I want more control over how they are displayed (whether alphabetical, by date going in or some other criteria). It would be helpful if I at least understood how this is happening now!
They just seem to go into the directory and pop up randomly in the list. This week I put in a new file into this directory and was surprised to see it go to near the bottom of the list, along with other files beginning with "b" (but at the top of the "b's"). I retitled it with a word beginning with "d" as an experiment and it did move it to another location in the list but not into any kind of alphabetical order that makes sense. The way I am reading this code is that it somehow puts it in reverse sort, with newer issues above issue 1. But the newest file is not going at the top or bottom of the list either! Nor does it seems to have anything to do with file size!
If someone could point to the part of this code that is controlling this, I might be able to break it apart and understand it better.
Thank you.
<?php
function get_list() {
$subdir = ".";
$articledir = getcwd() . "/" . $subdir;
$arg = getenv("QUERY_STRING");
$dir = opendir($articledir);
while ($file=readdir($dir)) {
if ((substr($file,0,1) != ".") && ($file!="index.php") &&
($file!="livemeeting.wmv")) {
$filelist[] = $file;
}
}
rsort ($filelist); // Reverse Sort (newer issues will be above issue 1)
foreach ($filelist as $file){
$len = strlen($file) - 4;
$title = substr($file, 0, $len);
$ext = mb_strtoupper (substr($file,$len+1));
$fullfile = $articledir . "/" . $file;
$size = filesize($fullfile);
$hsize = human_file_size ($size);
echo "<li><a href=\"$subdir/$file\">$title</a> ($ext, $hsize)</li>\n";
}
}
function human_file_size($size) {
$filesizename = array(" Bytes", " KB", " MB", " GB", " TB", " PB", " EB", " ZB", " YB");
return round($size/pow(1024, ($i = floor(log($size, 1024)))), 1) .
$filesizename[$i];
}
?>