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 Like 9 Dislike
Previous forums Next forums
Other forums

multiple recipients + dbuser mail recall
Hello,

I am building a php login script.

When the user registers the script will send

Linux socket programming
Where can I find a good introduction to socket programming?

Run function every 5 mins ??
I have a function PostMessage()

How can I run it every 5 mins ??

login box shows up again after logging in 2nd login works
Hello,

I am having trouble on my site Lockerz.rack111.com where when you login the login box

Multiple upload and Resize
I would like some help on my script I have the for my index.php

////

<html&

problem getting my contact form working
Yeah I know this is a pretty basic problem, but it's been a while since I've worked with PHP and I'm

Multiple while loops
I have several DB queries that I know should be returning results and aren't. I have a feeling it ha

fire away
i launched about 4 months ago as a lagit co. i have 2 paying clients, 1probono, 1 side progect, and

Am I setting up my sites oldschool?
Ok,

When I create a site I open a basic template that I have created that consists of a css f

$_FILES array
Ok,

I just started experimenting with PHP today. My goal right now is to have people be able

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash