Why does this file not return file names that start with numbers?
Posted on
16th Feb 2014 07:03 pm by
admin
This file returns a list of filenames to help populate a drop down in my form. For some reason it ignores any file names that begin with numbers, could anyone please tell my why and show me how to solve it?
Code: <?php
function buildFileList5($theFolder, $value) {
// Execute code if the folder can be opened, or fail silently
if ($contents = @ scandir($theFolder)) {
// initialize an array for matching files
$found = $output = array();
// Create an array of file types
$fileTypes = array('jpg','jpeg','gif','png','JPG');
// Traverse the folder, and add filename to $found array if type matches
$found = array();
foreach ($contents as $item) {
$fileInfo = pathinfo($item);
if (array_key_exists('extension', $fileInfo) && in_array($fileInfo['extension'],$fileTypes)) {
$found[] = $item;
}
}
// Check the $found array is not empty
if (!empty($found)) {
// Sort in natural, case-insensitive order, and populate menu
natcasesort($found);
//$selectedImage = ""; //default image
foreach ($found as $filename){
$sel = ""; //reset $sel
$selectedImage = ""; //default image
if($value == $filename) {
$sel = "selected="selected"";
$selectedImage = $filename;
}
$output[] = "<option value="$filename" $sel>$filename</option>n";
}
}
return (empty($output) ? '<option value="-1">No Items Found in `'.$theFolder.'`</option>' : '<option value="-1">Please select an Item</option'."n".join("n",$output));
}
}
?>
Thanks a million for any help on this
No comments posted yet
Your Answer:
Login to answer
160
9
Other forums
natcasesort works on one server but not on another
Hi
I have a problem that I was hoping that someone can help me with.
I'm trying to use
Undefined offset when using a flat file with pipe symbols
Hi, I've got a flat file/text file which I'm currently using as a member database for my site (not a
Ignore html and bbcode?
I've created a function to limit the amount of text according to the amount of words.
However
PHP login form help (Done Most of It)
Hi i am having a problem, when i try logging in it is always saying "Invalid Login" im not
having a small php error tha deals with the 'foreach'
Last night i was working on a script for a cart and it seemed to working good, until this morning. F
does anyone know a php script to send mail using gmails/googles free smtp server
cause i heard u can do that but i dont know how
Developing Ajax-enabled ASP.Net applications for the iPhone
I would like to develop Ajax web applications using Visual Studio that are optimized for the iPhone.
[newb] Image hosting help.
Hey there, I'm new to php, I know some basics and i can code PWN, I'm only 14 but I'm interested in
PHP IMAGE UPLOAD SCRIPT
Hi for the last week i have been looking for scripts that will upload a photo to a certain folder wh
Why will this program not run if the variables are not global?
Hey guys I have a kind of perplexing situation that is probably simple, but I can't seem to understa