0

Greetings All,

I am writing a php script that reads the contents of a folder and writes the files to the screen as a link. The folder has many files but the naming convention is the same. It is:

randomNumber_Date_Time.pdf

I need to scan the files and if the randomNumber is equal to the querystring input value, then display the file as a link on the page.

The random number can be from 1 to 9 digits in length. Here is the code snippet I am trying to get working.

<?php
$dir = "./inspection/";
if ($handle = opendir($dir)) {
  while (false !== ($file = readdir($handle))) { 
    if ($file != "." && $file != "..") { 
      //if (substr($file,strpos($file,'_')) == $_GET['qQID']) {
        echo substr($file,stripos($file,'_')) . "<br>";
        echo "<a href=\"./inspection/" . $file . "\">" . $file . "</a><br>"; 
      //}
    } 
  }
  closedir($handle); 
} 
?>

Thanks for looking!

John

1
Contributor
1
Reply
2
Views
7 Years
Discussion Span
Last Post by johnnc
0

I figured it out. Here is the working code.

<?php
$dir = "./inspection/";
if ($handle = opendir($dir)) {
	while (false !== ($file = readdir($handle))) { 
		if ($file != "." && $file != "..") { 
			if (substr($file,0,stripos($file,'_')) == $_GET['qQID']) {
				//echo substr($file,0,stripos($file,'_')) . "<br>";
				echo "<a href=\"./inspection/" . $file . "\">" . $file . "</a><br>"; 
			}
		} 
	}
	closedir($handle); 
} 
?>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.