This snippet will list files in drop down menu, truncate the file extension and capitalize the first letter of the file. I use it on my "theme changer" script but is useful if you want to only list the files in a directory and not its subdirectory.
By : shockingbird
<? /* ABOUT: This snippet will list all the files in the directory of your choice, truncate the file extension, capitalize the first letter and put it all in a drop down menu. The script will not list subdirectories so all you see are the files in your directory.
Feel free to use or modify to your liking.
USAGE: Change the $dirpath variable the directory you want to list.
AUTHOR: Written by shockingbird Visit www.glomer.net for more information tate at tatenations dot com for any questions */ echo "<form>"; //Looks into the directory and returns the files, no subdirectories echo "<select name='yourfiles'>"; //The path to the style directory $dirpath = "/path/to/your/directory"; $dh = opendir($dirpath); while (false !== ($file = readdir($dh))) { //Don't list subdirectories if (!is_dir("$dirpath/$file")) { //Truncate the file extension and capitalize the first letter echo "<option value='$file'>" . htmlspecialchars(ucfirst(preg_replace('/\..*$/', '', $file))) . '</option>'; } } closedir($dh); //Close Select echo "</select>"; echo "</form>"; ?>
DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.