Before we start with the next section, please make sure that you are familiar with file permissions. Pretty much everything in the File Permissions section applies to the directories. To navigate through a directory, you begin by opening the directory with opdir() function: $dir = opendir('directoryname'); As with reading and writing files, you create a pointer that can be referenced by the opened directory. To read the list of files within a directory you use the readdir() function, in a while loop: while($thedir=readdir($dir)){ and then you finally close the open directory with the closedir() function: closedir($dir); Other functions that we are going to use include: filesize() function - gives you the size of the file in bytes. filetime() - retrieves the modification time of a file. Both of these functions are going to help us to create a directory listing. Let's build a script that will show us the insides of a directory listing: Script: browsedir.php This script will list file names, file size and modification dates: <html> } Fig5. Shows a list of all the files in the current directory, represented here by a dot(.) Conclusion This concludes our file and directory handling exploration.
blog comments powered by Disqus |
|
|
|
|
|
|
|