Page 1 of 1

can't read a file in a dir, why?

Posted: Wed May 28, 2003 10:41 am
by SilvrWolf
This code works fine and populates my <option> BUT when I added a file called wellpath.gif it will not read it. if I drop the W (ellpath.gif) no problem, if I change the W to anything EXCEPT v,w,x,y,z again no problem. If I change it to the above letters it wont list. Wassup?
Thank you to all who can shed some light.
SilvrWolf

Code: Select all

<?php
//Insurance Image 
//ins_image_array  gets an array of images from the image directory

	$path = "../images/";

if ($dir = opendir($path)) {
  
  while($file = readdir($dir)) {
  
 
  if ($file != "." && $file != ".." && substr($file, -3) == "gif" || substr($file, -3) =="jpg"){
  $ins_image_array[] = $file;
	
	 }
	
  }  
  closedir($dir);
  } 
 
//	create a drop-down with the file names in the image directory
//	use the image_dir_arry to populate the drop down
//	use logic to select the image file name and place  SELECTED in its option tag

  for ($i=0; $i<count($ins_image_array)-1; $i++){
		echo "<option value="".$ins_image_array[$i].""";
		if ($ins_image_array[$i]=="no_image.gif"){
			echo "SELECTED";
			}
		echo ">".substr($ins_image_array[$i], 0, -4)."</option>\n";
		}
		
 
?>

Posted: Thu May 29, 2003 3:35 am
by Wayne

Code: Select all

for ($i=0; $i<count($ins_image_array)-1; $i++)&#123;
Im guessing it has something to do with the count - 1 and all files starting with v,w,x,y,z will be the last file and will be the last file which you are not getting to because of the - 1