Help with search file and ignoring file extensions

Discussion in 'PHP' started by crazyryan, Feb 25, 2007.

  1. #1
    Basically, below I have a search code where users can search through files and download them. However, if you search the extension, they all show, searching .gzr shows all of them. I want to ignore the file extension first of all, secondly, I want to be able to click a link like show all and all the files are listed.

    My code is as follows:
    <?php
    
    include_once("setup.php");
    
    $_POST['submit'] = addslashes($_POST['submit']); 
    
    if(isset($_POST['submit']))  { 
    
        $search  =  addslashes(htmlspecialchars($_POST['searchword']));
    
        if ($search) { 
    
            $brackets = "";
            for($ix=0; $ix<strlen($search); $ix++) {
                $brackets .= sprintf("[%s%s]", strtoupper($search[$ix]), strtolower($search[$ix]));
            }
    
            foreach(glob($folder . "*$brackets*") as $filename) {
                $i++;
                $filelink = $filename;
                $filename = end(explode("/", $filename));
                echo "<a href=\"$filelink\">$filename</a>" . "<br />\n";
            }
            
            if ($i > 0) {
                echo "<br>$i File(s) Found";
            } else {
                echo "No files found.";
            }
    
        } else {
        
            echo "No keyword entered.";
        
        }
    }
    
    ?>
    PHP:
     
    crazyryan, Feb 25, 2007 IP