How to read a list of files from a folder using PHP?

Web Development

I want to read a list the names of files in a folder in a web page using php. is there any simple script to acheive it?

1
Answers

Replies

Ans: Below is the code that can be used to read a list of files from a folder using PHP.


$files = array_values(array_filter(scandir($path), function($file) use ($path) { 


    return !is_dir($path . '/' . $file);


}));


foreach($files as $file){


    echo $file;


}

 
 

If you want to unleash your potential in this competitive field, please visit the Web Development course page for more information, where you can find the Web Development tutorials and Web Development frequently asked interview questions and answers as well.

 

This topic has been locked/unapproved. No replies allowed

Login to participate in this discussion.

Leave a reply

Before proceeding, please check your email for a verification link. If you did not receive the email, click here to request another.
Protected by Astra Security