Question:

PHP CODE to view all files under a folder in hosting server

by  |  earlier

0 LIKES UnLike

i need something like a php code file that i can go to that will display every file in that folder on my website. Is there a such a thing.. my host wont allow for files to be seen via sfdfd.com/images (displays all files under that directory if there is no index.php or html to block it.) it can be all images or what ever and it wont show but show up an error..

i need to actually be able to see what is in a folder (UPLOAD FOLDER) at any given time through a browser

 Tags:

   Report

1 ANSWERS


  1. This function will return a list of all the files in a directory:

    function dirList ($directory)

    {

        // create an array to hold directory list

        $results = array();

        // create a handler for the directory

        $handler = opendir($directory);

        // keep going until all files in directory have been read

        while ($file = readdir($handler)) {

            // if $file isn't this directory or its parent,

            // add it to the results array

            if ($file != '.' && $file != '..')

                $results[] = $file;

        }

        // tidy up: close the handler

        closedir($handler);

        // done!

        return $results;

    }

Question Stats

Latest activity: earlier.
This question has 1 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.