1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Simple Script to Search a Directory on my server?

Discussion in 'PHP' started by mokimofiki, Jan 15, 2013.

  1. #1
    Quite simply this is what i'm trying to do. I have a folder on my server full of images and I need to be able to search via a form and have it return the images that match the search. I can't seem to find anything simple to accomplish this.

    I'm not looking for anyone to do it for me but if anyone knows of a simple script already available or a resource to point me in the right direction that would be great.

    Thank you in advance.
     
    mokimofiki, Jan 15, 2013 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    Are you searching by the file name or something else? It wouldn't be very difficult to write a script that searching for some part of the file names.
     
    jestep, Jan 15, 2013 IP
  3. goliath

    goliath Active Member

    Messages:
    308
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    60
    #3
    I don't know if you'll find a script for this simple task.

    Just load the directory into an array and parse the filenames for the search string.

    Display those that match.
     
    goliath, Jan 15, 2013 IP
  4. mokimofiki

    mokimofiki Well-Known Member

    Messages:
    444
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    130
    #4
    Yes the files all have descriptive filenames so that they can be searched easily. An example filename would be "brandon at CES 2013 at booth 15602 with company x". There are like 100k image files though so was trying to avoid creating a database with all of them entered but want to allow someone to type "brandon ces 2013" and get a list of the files with that in the name.
     
    mokimofiki, Jan 15, 2013 IP
  5. goliath

    goliath Active Member

    Messages:
    308
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    60
    #5
    look:

    
    
    $file_list = scandir("load of pics here");
    
    foreach ($file_list as $file)
    {
        if (stristr($file, "Search Text"))
        {
        //   Output HTML
        }
    }
    
    
    Code (markup):
    So anyone that tries to sell/give you a tool for this is being, well, a tool :)
     
    goliath, Jan 15, 2013 IP
    mokimofiki likes this.
  6. mokimofiki

    mokimofiki Well-Known Member

    Messages:
    444
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    130
    #6
    Thank you this is perfect I was reading the array wrong before this will work great. I can search through the array for terms.

    Thank you.
     
    mokimofiki, Jan 15, 2013 IP
  7. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #7
    I think a database may still be more efficient especially if you're looping through every file each time you search for 1. File operations are often much slower and 100,000 is a decent enough size data set that it might be worthwhile to use a small database for the purpose. If you do go down that route, I would just insert the name to the database at the time the file is uploaded to the server, and delete it when a file is removed.
     
    jestep, Jan 15, 2013 IP