Seach code displaying folders incorrectly

I am a beginner and the code is intended to search for a file. It does seem after the SP upgraded the PHP version it now returns the incorrect file, and instead of showing only the existing files, it displays duplicates in the selection and displays the incorrect file.

Any assistance will be most welcome.

<?php require("global/constants.php"); require("gallery/sessionProcess.php"); require("global/dbro.php"); $stg = 0; if(isset($_POST["faction"])){ $stg = intval($_POST["faction"]); } $event = 0; if(isset($_POST["event_list"])){ $event = $_POST["event_list"]; } $prefix = 0; if(isset($_POST["img_prefix"])){ $prefix = $_POST["img_prefix"]; } ?> <? /*Page Header*/ ?> <?php print $stdheader?>
</head>
<body <?php print $bodyattributes ?> bgcolor='#FFFFFF'>
<table <?php print $tableattributes ?> width='100%' height='100%'><tr><td align='center'>
<? /*Main Template Table*/ ?>
	<table <?php print $tableattributes ?> height="100%" width='740'>
		<tr>
			<? /*Start Header Section*/ ?>
			<td rowspan='4' background='<?php print $grp?>/ltdbg.gif'><img src='<?php print $grp?>/1ptrans.gif' width='14'></td>
			<td bgcolor='#333366' height='65' colspan='2'><?php require("header.php")?></td>
			<td rowspan='4' background='<?php print $grp?>/rtdbg.gif'><img src='<?php print $grp?>/1ptrans.gif' width='24'></td>
			<? /*End Header Section*/ ?>
		</tr>
		<tr>
			<? /*Start Menu Section*/ ?>
			<?php require("menu.php")?>
			<? /*End Menu Section*/ ?>
			<td width='600' align='center' valign='top'>
			<? /*Start Main Content Section*/ ?>
			<table <?php print $tableattributes ?> width='100%' height='100%'>
				<tr>
					<td colspan='2' height='20'>
						<table <?php print $tableattributes ?> width='100%'>
							<tr valign='top'>
								<td width='1%'><img src='<?php print $grp?>/lheading.gif'></td>
								<td width='1%' class='pix12 bold' bgcolor='#FFFFFF' nowrap align='right'>Action Replay Event Search Facility</td>
								<td width='1%'><img src='<?php print $grp?>/rheading.gif' border='0'></td>
								<td width='97%' background='<?php print $grp?>/headingbg.gif' align='right'><img src='<?php print $grp?>/eheading.gif'></td>
							</tr>
						</table>
					</td>
				</tr>
				<tr>
					<td width='1' style='border-left:2px dotted orange;' valign='top'><img src='1ptrans.gif' width='1' height='1'></td>
					<td style='padding-right: 5px;' valign='top' class='pix12 para' width='100%'>
					<!-- ************************** Page Content Starts Here ****************************** -->
					<p>This search facility is intended for those people who attended an event covered by Action Replay photographers.</p>
					<p>You can search for a photo based on the event, photo prefix and photo number, e.g: <br>
					<b>Event: Hout Bay Agility Trials 1</b><br>
					<b>Photo Prefix: JA</b><br>
					<b>Photo No: JA-30</b></p>
					
					<?php
					$event_list = array();
					
					$handle = opendir($dir);
					while($file = readdir($handle)){
						if(
						$file !== "." &&
						$file !== ".." &&
						$file !== "action replay showcase gallery"
						){
							$event_list[] = $file;
						}
					}
					sort($event_list);
					
					echo "<form method='post' name='srcfrm' action='gallery/search_results.php'>\n";
					
					echo "<input type='hidden' name='faction' value=''>";
					
					if($event !== 0){
						echo "<input type='hidden' name='event' value='".$event."'>";
					}
					if($prefix !== 0){
						echo "<input type='hidden' name='prefix' value='".$event."'>";
					}
					
					
					echo "<table border=0>\n";
					
					$bgcolor = "";
					if($stg==0) $bgcolor="background-color: #FFCC33;";
					
					echo "<tr><td class='pix12 deepblue bold'>Select Event: </td>\n";
					echo "<td valign='top' colspan=2><select name='event_list' class='pix12' style='width: 240px; ".$bgcolor."' onchange='getPrefixList(this.value);'>\n";
					echo "<option value=''>Events List</option>\n";
					foreach($event_list as $list_dir){
						$selected = "";
						if(strtolower($event) == strtolower($list_dir)){ $selected = "selected";}
						echo "<option value='".$list_dir."' ".$selected.">".ucwords($list_dir)."</option>\n";
					}
					echo "</select>\n";
					echo "</td>\n";
					echo "</tr>\n";
					
					if($stg >= 1){
						
						echo "<tr>\n";
						
						$dir = "event_folders";
						$dir_r = realpath($dir);
						$event_path = $dir_r."/".$event;
						
						$prefix_list = array();
						
						echo "<td class='pix12 deepblue bold'>Select Prefix: </td>\n";
						
						if(is_dir($event_path)){
							$last_prefix = "";
							$handle = opendir($event_path);
							while($f = readdir($handle)){
								if(substr($f,-3)=="jpg"){
									$tmp = split("-",$f); 
									if($last_prefix !== trim($tmp[0])){
										//echo trim($tmp[0])."<br>";
										$prefix_list[] = trim($tmp[0]);}
									$last_prefix = trim($tmp[0]);
								}
							}
						}else{
							echo "<td>image dir not found</td>";
						}
						
						$bgcolor = "";
						if($stg==1) $bgcolor="background-color: #FFCC33;";
						
						if(count($prefix_list) > 0){
							echo "<td valign='top' colspan=2>\n";
							echo "<select class='pix12' style='width: 240px;".$bgcolor."' name='img_prefix' onchange='getFileList(this.value)'>\n";
							echo "<option value=''>Image Groups List</option>\n";
							foreach($prefix_list as $pre){
								$selected = "";
								if($prefix == $pre){$selected = "selected";}
								echo "<option value='".$pre."' ".$selected.">".$pre."</option>\n";
							}
							echo "</select>\n";
							echo "</td>\n";
						}
						echo "</tr>\n";
					}
					
					if($stg == 2){
						
						echo "<tr>\n";
						
						$dir = "event_folders";
						$dir_r = realpath($dir);
						$event_path = $dir_r."/".$event;
						
						$file_list = array();
						
						echo "<td class='pix12 deepblue bold'>Select Number: </td>\n";
						
						if(is_dir($event_path)){
							$last_prefix = "";
							$handle = opendir($event_path);
							while($f = readdir($handle)){
								if(substr($f,-3)=="jpg"){
									$tmp = split("-",$f); 
									if($prefix == trim($tmp[0])){
										$file_list[] = trim(str_replace(".jpg","",$f));
									}
								}
							}
						}else{
							echo "<td>no images found</td>";
						}
						
						$bgcolor = "";
						if($stg==1) $bgcolor="background-color: #FFCC33;";
						
						if(count($file_list) > 0){
							echo "<td colspan=2>\n";
							echo "<select class='pix12' style='width: 240px;".$bgcolor."' name='img_file'>\n";
							echo "<option value=''>Image File List</option>\n";
							
							natsort($file_list);
							
							foreach($file_list as $file){
								$selected = "";
								echo "<option value='".$file."'>".$file."</option>\n";
							}
							echo "</select></td>";
						}
						echo "</tr>\n";
												echo "<tr>";
					echo "<td class='pix12 deepblue bold'>No of pictures to<br> show before and<br> after match: </td>\n";
					
					echo "<td valign='top'>\n";
					echo "<select name='bapc' class='pix12'>\n";
					echo "<option value='0'>0</option>\n";
					echo "<option value='1'>1</option>\n";
					echo "<option value='2'>2</option>\n";
					echo "<option value='3'>3</option>\n";
					echo "<option value='4'>4</option>\n";
					echo "<option value='5'>5</option>\n";
					echo "<option value='6'>6</option>\n";
					echo "<option value='7'>7</option>\n";
					echo "<option value='8'>8</option>\n";
					echo "<option value='9'>9</option>\n";
					echo "</select>\n";
					
					echo "</td>\n";
					
					echo "<td valign='top' align='right'><input type='button' name='search' value='Search' align='abs_middle' onclick='chksrc_form();'></td>\n";
					echo "</tr>\n";		
					}
					
					
	//				echo "<tr>";
	//				echo "<td class='pix12 deepblue bold'>Photo No:</td>\n";
	//				echo "<td><input type='text' class='pix12' name='pno_txt' style='width: 240px;'></td>";
	//				echo "</tr>";
					
			
					
					echo "</table>\n";
					
					echo "</form>\n";
					
					?>
					
					
					<!-- ************************** Page Content Ends Here ****************************** -->						
					</td>
				</tr>
				<tr valign='top'>
					<td><img src='<?php print $grp?>/bheading.gif'></td>
					<td>&nbsp;</td>
				</tr>
			</table>
			<? /*End Main Content Section*/ ?>
			</td>
		</tr>
		<tr>
			<td colspan='2' height='23' align='right'><?php require("footer.php")?></td>
		</tr>
	</table>
</td></tr></table>
</body>
Sponsor our Newsletter | Privacy Policy | Terms of Service