PHP mkdir


PHP directory processing is actually part of the file processing, part of the processing function can refer to "PHP file processing" chapter.

PHP directory handling functions include:

  • mkdir(): Create Directory
  • is_dir(): Determine if a given file name is a directory
  • rmdir(): Delete directory
  • basename(): Returns files in the path
  • dirname(): Return to the directory in the path

mkdir()

mkdir() function is used to create a directory, the successful return of TRUE, otherwise return FALSE.

grammar:

bool mkdir(string dirname[, int mode])

The optional argument mode indicates the permissions given when the directory is created. By default, the maximum privilege is 0777.

example:

$dirname = 'testdir'
if (mkdir($dirname, 0700)) {
    echo "directory $dirname created successfully";
} else {
    echo "directory $dirname creation failed";
}

is_dir()

is_dir() function is used to check whether a given file name is a directory, the successful return of TRUE, otherwise return FALSE.

grammar:

bool is_dir(string filename)

example:

var_dump(is_dir('images')); // Output: bool(true)

Refer to reading

is_file(): Checks if the given file name is a normal file.




Copyright 2014-2017 by DeveloperTut.com. All Rights Reserved.
TwitterGoogle+Facebook