This article is mainly introduced in php tutorial directory operations functions is_dir, rd_dir, mkdir and other commonly used directory operation function examples.
* /
function dir_writeable ($ dir) / / Custom function extensions to create a writable directory
{
if (! is_dir ($ dir)) // if the given parameter is not a directory
{
@mkdir ($ dir, 0777); // Create a directory
echo "directory." $ dir. "build success!"
}
}
dir_writeable ("test"); // call a custom function to create the test directory
/ *
Executing this code will create a directory named: test in the current directory and output at the same time:
The directory test is successfully established
* /
$ dir = "test"; // define the directory
if (rmdir ($ dir)) // if the directory was deleted successfully
{
echo "directory." $ dir. "was successfully deleted!"; // output content
}
else
{
echo "Delete directory." $ dir. "An error occurred!";
}
//
$ path = "test.txt"; // Define the path
Echo $ path; / / output before processing
$ realpath = realpath ($ path); // Normalize the specified absolute path output
echo "<br>";
Echo $ realpath / / Output processed results
// See a complete example
function dir_writeable ($ dir) // Create a custom function extension
{
if (! is_dir ($ dir)) // if the given parameter is not a directory
{
@mkdir ($ dir, 0777); // Create a directory
}
if (is_dir ($ dir))
{
if ($ fp = @ fopen ("$ dir / test.txt", 'w')) // Open the file under the specified path write, if not exist
{
@fclose ($ fp); // Close the file handle
@unlink ("$ dir / test.txt"); // Delete the file
$ writeable = 1; // define the return value is true
}
else
{
$ writeable = 0; // Define the return value is false
}
}
return $ writeable; / / return value
} // custom function end