How to display all files from a folder using php

Hi i want to display files only from a folder,how to check if it is file or folder .give any sample code ,it will be very useful to me.:confused:

Everything you need can be found on

[FONT=courier new]opendir()[/FONT]

// open the current directory
$dhandle =  opendir( "./");
// define an array to hold the files
$files = array();

if ($dhandle) {
   // loop through all of the files
   while (false !== ($fname = readdir($dhandle))) {
      // if the file is not this file, and does not start with a '.' or '..',
      // then store it for later display
      if (($fname != '.') && ($fname != '..') &&
          ($fname != basename($_SERVER['PHP_SELF']))) {
          // store the filename
          $files[] = (is_dir( "./$fname" )) ? "(Dir) {$fname}" : $fname;
   // close the directory

this code retrive foldernames too. what wrong in it .i want to display the files name only

The following line is why everything is been included in the $files array.

$files[] = (is_dir( "./$fname" )) ? "(Dir) {$fname}" : $fname;

To retrieve only files the following will work

if (is_file($fname)) {
    $files[] = $fname;

i tried to delete the file using unlink command but it is not work. is it we have to pass extension in it. its extension is file .

No, the while loop contains the filename + the extension so no further logic is needed, my question to you is have you checked your error log as if unlink() is failing it’s most likely due to a permissions error.

thank you. its path problem i didnt give path in unlink . now it solves