Using PHP to read and sort a file directory
January 14, 2009
So you want to display the contents of a directory on your server. PHP can do it. You've already built something like it - but it's not drag-and-drop code. Which is a shame, really, because it's pretty basic functionality, and not hard to do ...
Anyways, here's a few little code snippets you can use. The longest of these (24 lines) allows you to sort by file name, file size, type of file, or date last modified. Sort direction can be specified - small to larger, older to more recent, etc.
Unique file names for uploaded files using PHP
August 28, 2008
Web page file uploads are very useful - custom front ends, absolute simplicity for end users, control over file types uploaded. But you'll need to guard against overwriting existing files when a file with the same name is submitted.
This four-line! PHP scriptlet creates a new file name from the original, appending an underscore and new, unique, sequentially incrementing number as required.
I also step through the code, bit by little bit - a neat little introduction to Regular Expression matching, if you're interested.
August 25, 2008
Rollovers are images that change appearance when the mouse moves over them: slick and functional cues that this, indeed, is an active link, and it'll take you somewhere.
Finally, we present a very few lines of code - easy to modify, and we tell you how. It works, in all the browsers we've tested it on. See it in action.
[ Read more ... ]