File names in directories

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

    #1

    File names in directories

    On my current website I have gallery pages with links to different
    galleries within that gallery section. The problem is, that I have to
    manually edit every single page when I want to add a new page so that every
    page now has a link that includes the new page number.

    Now I have been thinking that surely PHP could be used to automate this
    instead of me doing it every time I put a new gallery page online.

    What I'd like to know is if it is possible for PHP to read a file name,
    then use that to "echo" it into the HTML, then go to the next file name -
    do the same, until there are no more like sounding filenames in that
    directory.

    So for example, I have gallery01, gallery02, gallery03 webpages.

    I ask PHP to look for a match for "gallery", then add the file number "01",
    and echo it to the HTML page, and then do the same until there are no more
    "gallery" pages to be found in that directory.

    If possible, scould someone point me in which direction to do this (I don't
    need / want a complete solved solution :) ).

    Thanks.

    Dariusz
  • Shane Lahey

    #2
    Re: File names in directories

    Not sure if this is what you mean but you could use something like the
    following?

    <?php

    function find_pages($fol der)
    {
    $dir = @opendir($folde r);
    if (!is_resource($ dir))
    return false;

    $ret = array();
    while ($f = readdir($dir))
    {
    if (!preg_match('/^gallery\d+\.ht ml$/', $f))
    continue; // not a galleryXX.html file, goto next while()
    $ret[] = $f;
    }
    closedir($dir); // close this to free resources
    return $ret;
    }


    // now to locate your galleryXX.html files (if this is what you meant)
    // all you have to do is
    $pages = find_pages('/path/to/dir/with/galleryXX.html/files/');
    foreach ($pages as $id => $page)
    {
    printf("Found gallery page: %s<br />\n", $page);
    }

    ?>


    On Tue, 25 May 2004 15:30:58 GMT, ng@lycaus.plusY OURSHIT.com (Dariusz)
    wrote:
    [color=blue]
    >On my current website I have gallery pages with links to different
    >galleries within that gallery section. The problem is, that I have to
    >manually edit every single page when I want to add a new page so that every
    >page now has a link that includes the new page number.
    >
    >Now I have been thinking that surely PHP could be used to automate this
    >instead of me doing it every time I put a new gallery page online.
    >
    >What I'd like to know is if it is possible for PHP to read a file name,
    >then use that to "echo" it into the HTML, then go to the next file name -
    >do the same, until there are no more like sounding filenames in that
    >directory.
    >
    >So for example, I have gallery01, gallery02, gallery03 webpages.
    >
    >I ask PHP to look for a match for "gallery", then add the file number "01",
    >and echo it to the HTML page, and then do the same until there are no more
    >"gallery" pages to be found in that directory.
    >
    >If possible, scould someone point me in which direction to do this (I don't
    >need / want a complete solved solution :) ).
    >
    >Thanks.
    >
    >Dariusz[/color]

    Comment

    • Chung Leong

      #3
      Re: File names in directories

      "Dariusz" <ng@lycaus.plus YOURSHIT.com> wrote in message
      news:9FJsc.7119 $wI4.838326@war ds.force9.net.. .[color=blue]
      > On my current website I have gallery pages with links to different
      > galleries within that gallery section. The problem is, that I have to
      > manually edit every single page when I want to add a new page so that[/color]
      every[color=blue]
      > page now has a link that includes the new page number.
      >
      > Now I have been thinking that surely PHP could be used to automate this
      > instead of me doing it every time I put a new gallery page online.
      >
      > What I'd like to know is if it is possible for PHP to read a file name,
      > then use that to "echo" it into the HTML, then go to the next file name -
      > do the same, until there are no more like sounding filenames in that
      > directory.
      >
      > So for example, I have gallery01, gallery02, gallery03 webpages.
      >
      > I ask PHP to look for a match for "gallery", then add the file number[/color]
      "01",[color=blue]
      > and echo it to the HTML page, and then do the same until there are no more
      > "gallery" pages to be found in that directory.[/color]

      $files = glob("folder/gallery??.html" );
      foreach($files as $file) {
      ...
      }


      Comment

      Working...