Searching dir for file name

Discussion in 'PHP' started by rob7676, Jan 5, 2010.

  1. #1
    Is it possible to search a dir full of .pdf's for a specific file name or a file name in relevance to the keyword entered? If so, can someone please point me in the right direction?


    Thanks
     
    rob7676, Jan 5, 2010 IP
  2. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Use glob() to list all the pdf files, then match from there using either a regular expression or a simple string search
     
    JAY6390, Jan 5, 2010 IP
  3. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #3
    Here you go:

    <?php
    
    //directory path
    $dir = "forums/";
    
    //file to search for
    $search = 'filename';
    
    foreach (glob($dir . ''.$search.'.pdf') as $file) {
    
    //$file contains your searched file
    //Do something here ....
    
    }
    
    ?>
    PHP:
     
    danx10, Jan 5, 2010 IP
  4. rob7676

    rob7676 Peon

    Messages:
    82
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I got it working, even figured out how to use a wildcard. But there seems to be a problem(some what). It seems to be case sesative and I am hoping there is something I can do to make case insesative. Any ideas?
     
    rob7676, Jan 6, 2010 IP
  5. iAreCow

    iAreCow Peon

    Messages:
    85
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0