Find a file using php

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

    Find a file using php

    In a directory, how to find an image file with part of its filename is known
    and the file extension could be one of the following(jpg, tiff, bmp,png).

    The filename always begin between 1 to 3 alphabet, then a dash(-), and
    between 1-4 set of numbers and the extension could be in one of the
    following(in order of importance) - jpg, bmp, tif.

    If I know part/full of its filename, find the 1st match(just in case there
    are similar filename) with .jpg extension, if not found, then check with
    ..bmp extension, last check if it is with .tif extension.
    If still not found, then display no-image.jpg and exit.

    e.g:

    AA-123 one.tif
    AA-123 two.bmp
    AA-123 two.jpg
    AA-123.jpg
    B-34.jpg
    B-34xxxx.tif
    B yyyy.jpg
    ....
    ....



  • Jon Kraft

    #2
    Re: Find a file using php

    "Ruby Tuesday" <rubytuzdayz@ya hoo.com> wrote:
    [color=blue]
    > In a directory, how to find an image file with part of its filename is
    > known and the file extension could be one of the following(jpg, tiff,
    > bmp,png).[/color]

    Check out fnmatch():


    JOn

    Comment

    • Ruby Tuesday

      #3
      Re: Find a file using php

      Thank Jon.

      How do I put priorities on the findings if it returns a list of files?
      Thanks

      "Jon Kraft" <jon@jonux.co.u k> wrote in message
      news:Xns94A89D2 ACC5Ejonjonuxco uk@130.133.1.4. ..[color=blue]
      > "Ruby Tuesday" <rubytuzdayz@ya hoo.com> wrote:
      >[color=green]
      > > In a directory, how to find an image file with part of its filename is
      > > known and the file extension could be one of the following(jpg, tiff,
      > > bmp,png).[/color]
      >
      > Check out fnmatch():
      > http://uk.php.net/manual/en/function.fnmatch.php
      >
      > JOn[/color]


      Comment

      • Jon Kraft

        #4
        Re: Find a file using php

        "Ruby Tuesday" <rubytuzdayz@ya hoo.com> wrote:
        [color=blue]
        > "Jon Kraft" <jon@jonux.co.u k> wrote:[color=green]
        >> "Ruby Tuesday" <rubytuzdayz@ya hoo.com> wrote:
        >>[color=darkred]
        >> > In a directory, how to find an image file with part of its filename[/color][/color][/color]
        is[color=blue][color=green][color=darkred]
        >> > known and the file extension could be one of the following(jpg, tiff,
        >> > bmp,png).[/color]
        >>
        >> Check out fnmatch():
        >> http://uk.php.net/manual/en/function.fnmatch.php[/color]
        >
        > How do I put priorities on the findings if it returns a list of files?[/color]

        Well, you would match against jpg, bmp, etc... and build the priority
        logic in PHP code, e.g. if statement or switch()

        JOn

        Comment

        • Ruby Tuesday

          #5
          Re: Find a file using php

          Thanks again.

          The switch prioritize it from top to bottom isn't it? Thanks

          "Jon Kraft" <jon@jonux.co.u k> wrote in message
          news:Xns94A8ADB 7C25FEjonjonuxc ouk@130.133.1.4 ...[color=blue]
          > "Ruby Tuesday" <rubytuzdayz@ya hoo.com> wrote:
          >[color=green]
          > > "Jon Kraft" <jon@jonux.co.u k> wrote:[color=darkred]
          > >> "Ruby Tuesday" <rubytuzdayz@ya hoo.com> wrote:
          > >>
          > >> > In a directory, how to find an image file with part of its filename[/color][/color]
          > is[color=green][color=darkred]
          > >> > known and the file extension could be one of the following(jpg, tiff,
          > >> > bmp,png).
          > >>
          > >> Check out fnmatch():
          > >> http://uk.php.net/manual/en/function.fnmatch.php[/color]
          > >
          > > How do I put priorities on the findings if it returns a list of files?[/color]
          >
          > Well, you would match against jpg, bmp, etc... and build the priority
          > logic in PHP code, e.g. if statement or switch()
          >
          > JOn[/color]


          Comment

          Working...