FREE PHP Scripts and Snippets

Ready to use Free PHP scripts and snippets to use in your projects.
All Free Scripts & Snippets Complete PHP Scripts

PHP Code to list all files in a folder

>> Share on Facebook & Impress your friends <<

This PHP Code snippet lists all files in a folder and hyperlinks them accordingly. Very clean, easy to use function. Just cut and paste.



This is a simple function to list all files in a specific folder on your web server.

Function require path to the folder to be passed on to it.

It then echoes the Hyperlinked list of files.

function listFilesInDirectory($folder)
	// Function gets name of folder 
    {  // Works only if the folder is found
        if($handle = opendir($folder))
        { // Now it has successfully opened the folder to get its content. 
            while(($file = readdir($handle)) !== false)
            {  // Now we look through all file and folder names
                if($file != "." && $file != ".." && $file != "Thumbs.db")
                { // Here we ignore some file names like [.]  [..] and Thumbs.db files/folders
				// Now we print the hyperlinked list of files/folders 
				// <a> tag is for links
				// <br> tag is for line feeds.
                    echo '<a target="_blank" href="'.$folder.$file.'">'.$file.'</a><br>'."\n";
            closedir($handle);  // This does some housekeeping
}  // End of List Files In directory function
// Let Us call the function and see how it goes! 


Request Custom Snippet

Just $5 Onwards


Previously Ordered Snippets

I want folder to gallery PHP Script. I will have all images in one folder. And PHP Script should show those images on a web page. It should page it will 25 images per page.
Price $25 Order Now

I need PHP folder listing script which shows list of sub-folders and clicking on sub-folder should show sub-folder in it.
Price $15 Order Now

I want PHP code to show folder permissions.
Price $5 Order Now

I want PHP Script to rename all files in a folder by appending certain text string to file names.
Price $5 Order Now

Random PHP Scripts and Snippets

Create URL Slug from text string [PHP]

PHP Script to create URL from string. It retails only URL Safe characters in the strings. So, now easily create...

Detect Valid Email address with PHP

A very simple php snippet to check if an email id is valid or not. If the email address is...

Generate Random Password in PHP

PHP Script to Generate Random Password. You can set the list of characters that you want to be used in...

Make URLs in plain text clickable [PHP]

This is a simple PHP function to parse text provided and automatically hyperlink the links in the text.

PHP extract multiple emails from text

PHP Script to scan a text and extract all email ids contained in the text. It outputs email addresses as...

[PHP] Time ago calculation function

It is a very nice PHP time ago function. You gave pass any date to it and it will tell...

Free PHP folder to gallery script

100% Free PHP folder to gallery script. Just give the name of folder and it will generate gallery of all...

Extracting all numbers from a String [PHP]

This PHP function extracts all numbers from a String and prints them as a comma separated list of numbers. Ready...