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
strtotime issue
Hey all,
I'm playing around with some code, and basically the idea is:
Person changes
Help With editting and deleting form
So look at this image :
http://img194.imageshack.us/img194/8272/snapshot5f.png
This table
how to easy edit text, with box? Help.
Hi.
I have a little problem. I'm doing a webpage for my aunt and I would like to make it as easy
calculator
I can't figure out why this code doesn't work. No error messages. Page loads.
Code: <
how can i expire the submitted page using session.
hi,
i'm new to php world.
i'm using "post" method.
when i submit it,data goes to
Creating Images from images in PHP
Okay well I am trying to make a 'dynamic' calender image with PHP.
I have images like this:
use an array from 1 class in a second class
I have a class that adds data to an array
Then I have a second class and I need to check if t
Strange php code found on my website
I got hacked and the following code was placed within my files:
Code: [Select]<?
/*
Simple Variable Question
Hi everyone.... again,
I am really getting into php still. Learning more every day. I love it
update post issues
I am trying to create an update to a post function, while the update does occur, the page routing an