I've searched forums and I've discovered that if I want to sort the files I have in a folder by date modified the I will need an array. That makes sense. How to do it, doesn't. Will the array change the modification date when it uses the file? Here is the code I have to pull the name - date:
while (($file = readdir($handle))!==false)
$file_list .= $file . " - " . date("F d Y .",filectime("./content/uploaded/" .$file));}
How do I add an array to sort without screwing up my code?
The files will now be sorted by date created. From here you can create the string and the date using a foreach on the $aFiles instead. The key is your filename (which will be unique of course), and the value is the create time.
There is a way to do this with Iterators as well, although (as much as I like objects) they are a little difficult to do properly since PHP doesn't have a default comparable method on its objects.
Reading the file's name won't issue any type of touch command so the modification date will not change.
Very close, thank you. But it creates another problem. $key displays the file name correctly (67023-fish.jpg), but $key to make the image path adds some characters (h ttp://www.mysite.com/flex-graphics/content/uploaded/67023-fish.jpg%3C/a) The %3C/a makes the image not appear. What would it do that? Can we fix it, or add some code to take off the last 5 haracters?
The key shouldn't have a path in it at all, but it could be a directory since you don't specify it should be for files only. Its not recursive, so it will only have the current level.
%3C is a < character. That cannot come from reading the filenames as < is an illegal character in a filename. If I recall linux will accept < and > in its filename, but should be avoided. It is unlikely this is the case here.
The HTML you have is invalid. This is malformed: <img src=./content/uploaded/" . $key . "</a>. You have to change the <img> to be single sided, and the entire <img/> tag can be wrapped with an anchor, but you cannot have an anchor as a part of the attribute in the source as you have it now. That should be using '<img src="./content/uploaded/' . $key . '" alt=""/>' and can be wrapped with the anchor if desired. You'll need to add additional code to pull out just files though, this one will let you follow directories as well.
Not sure why you hijacked a thread in a completely different topic, but to answer your question you only have the option of hashtables in PHP since PHP does not have native arrays in it.
If you mean by recordset fetching with row versus assoc, use assoc since it doesn't contain any substantial overhead to it and it makes it obvious which you are accessing.