opening a file when you do not know the full name

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

    opening a file when you do not know the full name

    I have a directory into which I upload pictures. I know the
    entire file name other than the extension.

    file_exists will return true when I give it a wildcard extension,
    but I can't figure out the best way to determine the extension
    for fopen.

    I sure don't want to troll through the entire directory with
    readdir.

    I would appreciate suggestions.

    bill
  • pangea33

    #2
    Re: opening a file when you do not know the full name


    bill wrote:
    I have a directory into which I upload pictures. I know the
    entire file name other than the extension.
    >
    file_exists will return true when I give it a wildcard extension,
    but I can't figure out the best way to determine the extension
    for fopen.
    >
    I sure don't want to troll through the entire directory with
    readdir.
    >
    I would appreciate suggestions.
    >
    bill
    If you use the "find" command with exec() you can get a list of files
    that match your criteria. Essentially using the filename you already
    know, and then a wildcard for the extension...

    find /var/www/directory/pics2 -name "weddingphoto.* "

    For me this outputs: /var/www/directory/pics2/weddingphoto.jp g

    If you output the results into a file or into a variable, you can then
    parse it for whatever is relevent to you.

    find /var/www/directory/pics2 -name "weddingphoto.* " >
    /var/www/directory/pics2/results.txt

    Comment

    • Michael Fesser

      #3
      Re: opening a file when you do not know the full name

      ..oO(bill)
      >I have a directory into which I upload pictures. I know the
      >entire file name other than the extension.
      >
      >file_exists will return true when I give it a wildcard extension,
      >but I can't figure out the best way to determine the extension
      >for fopen.
      Find pathnames matching a pattern


      Micha

      Comment

      • pangea33

        #4
        Re: opening a file when you do not know the full name

        Michael Fesser wrote:
        .oO(bill)
        >
        I have a directory into which I upload pictures. I know the
        entire file name other than the extension.

        file_exists will return true when I give it a wildcard extension,
        but I can't figure out the best way to determine the extension
        for fopen.
        >
        Find pathnames matching a pattern

        >
        Micha
        Not so sure that I agree using a function in an application, that
        communicates with the OS via a webserver, is a better choice than
        something native to the operating system, but this solution will
        definitely work. Probably easier to handle the result set too.

        Comment

        • bill

          #5
          Re: opening a file when you do not know the full name

          pangea33 wrote:
          Michael Fesser wrote:
          >.oO(bill)
          >>
          >>I have a directory into which I upload pictures. I know the
          >>entire file name other than the extension.
          >>>
          >>file_exists will return true when I give it a wildcard extension,
          >>but I can't figure out the best way to determine the extension
          >>for fopen.
          >http://www.php.net/glob
          >>
          >Micha
          >
          Not so sure that I agree using a function in an application, that
          communicates with the OS via a webserver, is a better choice than
          something native to the operating system, but this solution will
          definitely work. Probably easier to handle the result set too.
          >
          In my case where there is only one result, should work a treat.

          Thanks

          bill

          Comment

          Working...