search a web server directory

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Hostos

    search a web server directory

    Hello All,

    Please advice...I would like to do this in php, but I am open
    to suggestions


    I am going to place about 6 gigs of jpeg pictures on a web
    server. And. I want to allow a user to go to a web page and type in
    the name of a file, and if the file is found in the particular
    directory on the server, the jpeg picuture will then be display in the
    web browser.


    I am thinking about just having a php script that will search
    the particular directory, but I am not sure where to get started.
    Also, will this bogg down the server.

    And, in case anyone is wondering...thi s is being done for a
    department at my university.


    thanks,
    Hostos
  • Pedro Graca

    #2
    Re: search a web server directory

    Hostos wrote:[color=blue]
    > I want to allow a user to go to a web page and type in
    > the name of a file, and if the file is found in the particular
    > directory on the server, the jpeg picuture will then be display in the
    > web browser.[/color]
    [color=blue]
    > I am thinking about just having a php script that will search
    > the particular directory, but I am not sure where to get started.[/color]

    <?php
    // this script is the action specified for the form that asks for the
    // file name (or the same script that outputs the form
    $filename = $_POST['filename'];
    $directory = 'images/2003/';
    if (isfile($direct ory . $filename)) {
    echo '<img src="', $directory . $filename, '"/>';
    } else {
    echo '<p class="error">f ile ', $filename, ' does not exist in ',
    $directory, '.</p>';
    }
    ?>
    [color=blue]
    > Also, will this bogg down the server.[/color]

    I don't know. If it does maybe it's better to check for filename in a
    filelist text file generated automaticcaly (by a cron job?)
    --
    --= my mail box only accepts =--
    --= Content-Type: text/plain =--
    --= Size below 10001 bytes =--

    Comment

    • CountScubula

      #3
      Re: search a web server directory

      "Hostos" <hmon6710@hotma il.com> wrote in message
      news:e9f4a21b.0 403012133.75c1d ce1@posting.goo gle.com...[color=blue]
      > Hello All,
      >
      > Please advice...I would like to do this in php, but I am open
      > to suggestions
      >
      >
      > I am going to place about 6 gigs of jpeg pictures on a web
      > server. And. I want to allow a user to go to a web page and type in
      > the name of a file, and if the file is found in the particular
      > directory on the server, the jpeg picuture will then be display in the
      > web browser.
      >
      >
      > I am thinking about just having a php script that will search
      > the particular directory, but I am not sure where to get started.
      > Also, will this bogg down the server.
      >
      > And, in case anyone is wondering...thi s is being done for a
      > department at my university.
      >
      >
      > thanks,
      > Hostos[/color]



      just a thought, but if its a linux platform you can try the locate command,
      and pass through grep for the parent directory:

      // find all house pictures
      $searchString = "house";
      $files = `locate $searchString | grep '/www/parent/dir/pictures/'`;

      to update the locate db, type this on the command line:
      updatedb

      or wait untill the next day, it should be already in a cron job

      --
      Mike Bradley
      http://www.gzentools.com -- free online php tools


      Comment

      • Andy Jeffries

        #4
        Re: search a web server directory

        CountScubula wrote:[color=blue]
        > just a thought, but if its a linux platform you can try the locate command,
        > and pass through grep for the parent directory:
        >
        > // find all house pictures
        > $searchString = "house";
        > $files = `locate $searchString | grep '/www/parent/dir/pictures/'`;[/color]

        Remember though that if the user is typing in $searchString - NEVER EVER
        DO THE SECOND LINE SHOWN ABOVE!

        If the user types "a; rm -f /some/file/here; locate a" as $searchString
        it will delete the file (if Apache has permissions) and continue as if
        nothing had happened....

        Cheers,


        Andy

        Comment

        • CountScubula

          #5
          Re: search a web server directory

          "Andy Jeffries" <newnews@seirff ej.reverse.prev ious.word.co.uk > wrote in
          message news:1078234988 .7573.0@echo.uk .clara.net...[color=blue]
          > CountScubula wrote:[color=green]
          > > just a thought, but if its a linux platform you can try the locate[/color][/color]
          command,[color=blue][color=green]
          > > and pass through grep for the parent directory:
          > >
          > > // find all house pictures
          > > $searchString = "house";
          > > $files = `locate $searchString | grep '/www/parent/dir/pictures/'`;[/color]
          >
          > Remember though that if the user is typing in $searchString - NEVER EVER
          > DO THE SECOND LINE SHOWN ABOVE!
          >
          > If the user types "a; rm -f /some/file/here; locate a" as $searchString
          > it will delete the file (if Apache has permissions) and continue as if
          > nothing had happened....
          >
          > Cheers,
          >
          >
          > Andy[/color]

          True, but this was not meant to be a end all script snippet, however, I
          should have seen that comming.

          REVISED:

          // find all house pictures
          $searchString = "house";
          $searchString = strtr($searchSt ring,";./ ","----"); // andd chrs to remove,
          as to keep safe
          $files = `locate $searchString | grep '/www/parent/dir/pictures/'`;

          --
          Mike Bradley
          http://www.gzentools.com -- free online php tools


          Comment

          • Andy Jeffries

            #6
            Re: search a web server directory

            CountScubula wrote:[color=blue][color=green][color=darkred]
            >>>// find all house pictures
            >>>$searchStrin g = "house";
            >>>$files = `locate $searchString | grep '/www/parent/dir/pictures/'`;[/color]
            >>
            >>Remember though that if the user is typing in $searchString - NEVER EVER
            >>DO THE SECOND LINE SHOWN ABOVE!
            >>
            >>If the user types "a; rm -f /some/file/here; locate a" as $searchString
            >>it will delete the file (if Apache has permissions) and continue as if
            >>nothing had happened....[/color]
            >
            > True, but this was not meant to be a end all script snippet, however, I
            > should have seen that comming.[/color]

            I know you knew that Mike (we've had technical chats a few times IIRC)
            but I thought it prudent for anyone finding the post through Google or
            maybe the OP.

            Cheers,


            Andy

            Comment

            • CountScubula

              #7
              Re: search a web server directory

              "Andy Jeffries" <andy@seirffej. reverse.previou s.word.co.uk> wrote in message
              news:1078305967 .11140.0@ersa.u k.clara.net...[color=blue]
              > CountScubula wrote:[color=green][color=darkred]
              > >>>// find all house pictures
              > >>>$searchStrin g = "house";
              > >>>$files = `locate $searchString | grep '/www/parent/dir/pictures/'`;
              > >>
              > >>Remember though that if the user is typing in $searchString - NEVER EVER
              > >>DO THE SECOND LINE SHOWN ABOVE!
              > >>
              > >>If the user types "a; rm -f /some/file/here; locate a" as $searchString
              > >>it will delete the file (if Apache has permissions) and continue as if
              > >>nothing had happened....[/color]
              > >
              > > True, but this was not meant to be a end all script snippet, however, I
              > > should have seen that comming.[/color]
              >
              > I know you knew that Mike (we've had technical chats a few times IIRC)
              > but I thought it prudent for anyone finding the post through Google or
              > maybe the OP.
              >
              > Cheers,
              >
              >
              > Andy[/color]

              Hi Andy, I didn't take any offense to it, I totally agree with you. Funny
              thing is, someone posted a piece of code and asked what was wrong, and I
              went to thier site, and brough it down several times (with thier permission)
              and exploited several things, from just such a type of thing.

              Thanks for keeping me on my toes. :)

              --
              Mike Bradley
              http://www.gzentools.com -- free online php tools


              Comment

              • Chung Leong

                #8
                Re: search a web server directory

                Uzytkownik "Pedro Graca" <hexkid@hotpop. com> napisal w wiadomosci
                news:c21kr1$1lm 8pu$1@ID-203069.news.uni-berlin.de...[color=blue][color=green]
                > > Also, will this bogg down the server.[/color]
                >
                > I don't know. If it does maybe it's better to check for filename in a
                > filelist text file generated automaticcaly (by a cron job?)[/color]

                Or cache the list and do a mtime comparison between the file and the
                directory. It probably takes longer though for PHP to find an item in an
                array then for the file system to locate a file, since there isn't function
                that performs binary search.


                Comment

                Working...