Source Code of View and Delete Files From a Directory using PHP
You can view files from a directory using the following two methods in PHP.
In the first method, we use opendir() and readdir() functions.
Example:
1 2 3 4 5 6 7 8 9 |
if ($handle = opendir('.')) { while (false !== ($entry = readdir($handle))) { if ($entry != "." && $entry != "..") { echo "$entry\n<br>"; } } closedir($handle); } |
In the second method, we use scandir() function. This function returns the files from the directory in a form of an array.
Example:
1 2 3 4 5 6 7 |
<?php $direc = "test/"; $asc = scandir($direc); $des = scandir($direc,1); print_r($asc); print_r($des); ?> |
Delete Files From The Directory – Source Code in PHP
You can delete files from the directory using unlink() function in PHP.
Example:
1 2 3 4 5 |
if(isset($_POST['del'])) { $FN = $_POST['FN']; unlink('test/'.$FN); } |
Output
View Method opendir() and readdir().
View Method scandir().
Delete Files.
Download – How to View and Delete Files From a Directory using PHP