Microsoft Word - Core PHP Programming Using PHP to Build Dynamic Web Sites

(singke) #1

boolean mkdir(string directory, integer mode)


The mkdir function creates a new directory with the supplied name. Permissions will be
set based on the mode argument, which follows the same rules as chmod. On Windows the
mode argument is ignored. You can use the rmdir function to remove a directory.


<?
if(mkdir("myDir", 0777))
{
print("directory created");
}
else
{
print("directory cannot be created");
}
?>


integer opendir(string directory)


The opendir function requires a directory name and returns a directory handle. This
handle may be used by readdir, rewinddir, and closedir. The dir function described
above provides an alternative to this group of functions.


<?
// print the current directory in a table
print("<TABLE BORDER=\"1\">\n");


// create header row
print("\n");
print("Filename\n");
print("File Size\n");
print("\n");


// open directory
$myDirectory = opendir(".");


// get each entry
while($entryName = readdir($myDirectory))
{
print("");
print("$entryName");
print("<TD ALIGN=\"right\">");
print(filesize($entryName));
print("");
print("\n");
}


// close directory
closedir($myDirectory);

Free download pdf