Displaying filenames as Hyperlinks on a page?

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

    #1

    Displaying filenames as Hyperlinks on a page?

    Hi,

    I'd like to write a loop that will create a hyperlink on a page for
    every single file on a directory. As an example, if my directory
    contains:

    test.txt
    test1.txt
    test2.txt,

    The page should then contain 3 hyperlinks pointing to these files and
    the user just have to click the one he wants to download or read.

    Thanks.
  • kingofkolt

    #2
    Re: Displaying filenames as Hyperlinks on a page?

    <?php
    $directory_name = "dir"; // change this to reflect your directory name
    $dh = opendir($direct ory_name);
    while ($file = readdir($dh)) {
    if (is_dir("$direc tory_name/$file")) {
    continue;
    }
    print "<a href=\"$directo ry_name/$file\">$file</a><br>\n";
    }
    closedir($dh);
    ?>


    "circuit_breake r" <circuit_breake r@canada.com> wrote in message
    news:2863e14b.0 403301154.68d34 662@posting.goo gle.com...[color=blue]
    > Hi,
    >
    > I'd like to write a loop that will create a hyperlink on a page for
    > every single file on a directory. As an example, if my directory
    > contains:
    >
    > test.txt
    > test1.txt
    > test2.txt,
    >
    > The page should then contain 3 hyperlinks pointing to these files and
    > the user just have to click the one he wants to download or read.
    >
    > Thanks.[/color]


    Comment

    • Andy Hassall

      #3
      Re: Displaying filenames as Hyperlinks on a page?

      On Tue, 30 Mar 2004 20:37:55 GMT, "kingofkolt " <jessep@comcast .net> wrote:
      [color=blue]
      >while ($file = readdir($dh)) {[/color]

      Until you have a file called '0', of course.

      while (($file = readdir($dh)) !== false) {

      --
      Andy Hassall <andy@andyh.co. uk> / Space: disk usage analysis tool
      http://www.andyh.co.uk / http://www.andyhsoftware.co.uk/space

      Comment

      • kingofkolt

        #4
        Re: Displaying filenames as Hyperlinks on a page?

        you're right, i forgot about that...

        another way to redo that line is:

        while (!is_bool($file = readdir($dh))) {

        because readdir() returns false when there are no more files

        - JP

        "Andy Hassall" <andy@andyh.co. uk> wrote in message
        news:clrj60l072 s1k7km9sjm01id6 t33eg200i@4ax.c om...[color=blue]
        > On Tue, 30 Mar 2004 20:37:55 GMT, "kingofkolt " <jessep@comcast .net> wrote:
        >[color=green]
        > >while ($file = readdir($dh)) {[/color]
        >
        > Until you have a file called '0', of course.
        >
        > while (($file = readdir($dh)) !== false) {
        >
        > --
        > Andy Hassall <andy@andyh.co. uk> / Space: disk usage analysis tool
        > http://www.andyh.co.uk / http://www.andyhsoftware.co.uk/space[/color]


        Comment

        • Agelmar

          #5
          Re: Displaying filenames as Hyperlinks on a page?

          kingofkolt wrote:[color=blue]
          > you're right, i forgot about that...
          >
          > another way to redo that line is:
          >
          > while (!is_bool($file = readdir($dh))) {
          >
          > because readdir() returns false when there are no more files
          >
          > - JP[/color]

          Or, perhaps a bit more clearly,
          while(($file = readdir($dh)) !== false)


          Comment

          • Andy Hassall

            #6
            Re: Displaying filenames as Hyperlinks on a page?

            On Tue, 30 Mar 2004 23:44:04 -0500, "Agelmar" <ifetteNOSPAM@c omcast.net> wrote:
            [color=blue]
            >kingofkolt wrote:[color=green]
            >> you're right, i forgot about that...
            >>
            >> another way to redo that line is:
            >>
            >> while (!is_bool($file = readdir($dh))) {
            >>
            >> because readdir() returns false when there are no more files
            >>
            >> - JP[/color]
            >
            >Or, perhaps a bit more clearly,
            >while(($file = readdir($dh)) !== false)[/color]

            There's an echo in here ;-) See the post he replied to but snipped ;-)

            --
            Andy Hassall <andy@andyh.co. uk> / Space: disk usage analysis tool
            http://www.andyh.co.uk / http://www.andyhsoftware.co.uk/space

            Comment

            • Agelmar

              #7
              Re: Displaying filenames as Hyperlinks on a page?

              Andy Hassall wrote:[color=blue]
              > On Tue, 30 Mar 2004 23:44:04 -0500, "Agelmar"
              > <ifetteNOSPAM@c omcast.net> wrote:
              >[color=green]
              >> kingofkolt wrote:[color=darkred]
              >>> you're right, i forgot about that...
              >>>
              >>> another way to redo that line is:
              >>>
              >>> while (!is_bool($file = readdir($dh))) {
              >>>
              >>> because readdir() returns false when there are no more files
              >>>
              >>> - JP[/color]
              >>
              >> Or, perhaps a bit more clearly,
              >> while(($file = readdir($dh)) !== false)[/color]
              >
              > There's an echo in here ;-) See the post he replied to but snipped
              > ;-)[/color]

              LOL I didn't look that far down. I just saw something incredibly ugly and
              couldn't resist posting ^-^.


              Comment

              Working...