Read Files in folder

This tutorial explains how to read all the files in folder. The program read all files in folder and display the files as table as shown below.

Refer this tutorial there I am explaining how to delete the selected files.There is checkbox next to each file and it deletes the selected file on button submit.


 public function readFiles() {
        $thelist = '';
        if ($handle = opendir('upload/')) {
            $thelist .= '<form method="post"><table>';
            $thelist .= '<tr><th colspan="2" align="left"><h2>List all files</h2></th></tr>';
            while (false !== ($file = readdir($handle)))
                   if ($file != "." && $file != "..")
                         $thelist .= '<tr><td><input type="checkbox" name="selectedFiles[]" value="'.$file.'"></td><td><a href="'.$file.'">'.$file.'</a></td></tr>';
                $thelist .=  '<tr><td colspan="2" align="left"><input type="submit" value="Delete selected files" name="delete" style="height:30px;width:150px; margin-top:8px;"></td></tr>';
                $thelist .= '</table></form>';
        echo $thelist;

Share this Tutorial