Jump to content

Why does this file not return file names that start with numbers?


spenceddd

Recommended Posts

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?

 

<?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.

 

Spencer

 

 

Link to comment
Share on other sites

Yes of course, here is the file list:

 

weekScan.jpg

1Autumn Leaves.jpg

Creekbo.jpg

Croak.jpg

Desert Landscape.jpg

Dock.jpg

Fluence-1600x1200.jpg

Garden.jpg

Green Sea Turtle.jpg

IMG_0754.JPG

Tree.jpg

 

of which only the item: 1Autumn Leaves.jpg odesn't load into the drop down list. Also if i change the names of the other items to inlcude numbers at the start of the name, they stop working too.

 

You can see the form here where the image box drop downs are the drop downs in question.  http://www.spencercarpenter.co.uk/portfolioAppFiles/simpleForm.php

 

Hopefully that helps a bit.

 

Spencer

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.