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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
SilvrWolf
Forum Newbie
Posts: 7
Joined: Sun Aug 11, 2002 11:00 am

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

Post 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";
		}
		
 
?>
User avatar
Wayne
Forum Contributor
Posts: 339
Joined: Wed Jun 05, 2002 10:59 am

Post 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
Post Reply