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

Array becomes unset by itself?
Hi,

I have a bit of experience with PHP but not extensive. It seems I cannot store any items

Most basic form question ever?
Hello,

I want to use this snippet to make sure the fields in a form are ok before processing

Require select-option functionality in Module Pool Programming
Hi Gurus,

I am doing a development by Module Pool on Warehouse Management. For that devel

socket communication between c++/java and sending image
hi,

i have a class in c++ called win32_sockserver which creates socket to java. i am trying

using a loop help
Hi guys , i need some help. I have this loop :
while ($row = mysql_fetch_assoc($Result)) { ?&

How to get variable value on next page
Hello friends
i am working on payentry page ..there i have this code.........

Can php detect connection speed and thereafter swap out elements?
No code to post, lads, yet. Just looking for a yay or nay at this stage:

Can a php script be

help with database debug pls
Parse error: syntax error, unexpected T_ELSE in /home/content/m/e/s/mesick/html/students/05/php/chec

Internal Server Error issues
This has been bothering me for weeks and I've been trying to solve it without asking for help, but e

How to validate from 2 possible answers
Hi

I hope somebody can help me with what will probably be really simple, I'm pulling my hair

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