The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.


Results 1 to 2 of 2

Thread: Listing files in a folder.

  1. #1
    58
    posts
    Registered User

    Listing files in a folder.

    Hi!

    I'm trying to list some files in a folder and then link it to itself, so users can access it.
    here is my code:
    PHP Code:
    <?PHP
    $dir 
    'images/';
    $files scandir($dir);
    foreach (
    $files as &$file) {
    if (
    $file!='.' && $file!='..' )
    {
    echo 
    '<a href="images/'$file.'">'$file.'</a><br>';
    }
    }
    ?>
    I've tried a couple of different things but can't wrap my head around it.

    Thanks a lot in advance!

  2. #2
    58
    posts
    Registered User
    I've got it working, after some google searching!

    For others that might need this here's the code:

    PHP Code:
    <?php

    $dir
    ="images/"// Directory where files are stored

    if ($dir_list opendir($dir))
    {
    while((
    $filename readdir($dir_list)) !== false)
    {
    ?>
    <p><a href="images/<?php echo $filename?>"><?php echo $filename;
    ?></a></p>
    <?php
    }
    closedir($dir_list);
    }
    s

    ?>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012