Creating a search box to search photos on website's server

Discussion in 'Web Design and Development' started by htg, Feb 4, 2012.

  1. htg macrumors regular

    May 2, 2009
    The title probably hasn't explained it at all well, so let me clarify:

    I know basic HTML, and I'm wondering how you would do this.

    I want to be able to have a search box on my site that will allow visitors to search for photos that are hosted on the site's server.

    So, totally random example: if you've uploaded a photo of a cat to the photos folder on the website's server entitled 'cat.jpg' I want people who visit the site to be able to type cat into the search box so that they can find and view the photo.

    I don't think it's super hard to do and I don't think it would require a database either as all you're doing is searching one folder.

    Any help appreciated.
  2. ppc_michael Guest


    Apr 26, 2005
    Los Angeles, CA
    HTML can't do that by itself; you'll need a script that runs on the server that can look in the photos directory and return the results formatted as HTML.

    A very popular scripting language is PHP. Functions that you will likely find useful include scandir() to get a directory listing, foreach() to iterate through each entry (file name) in that directory listing, and stripos() to determine if the search string matches part of the filename.

Share This Page