This article mainly introduces examples of common directory operation functions such as is_dir, rd_dir, mkdir and so on in PHP.
This article mainly introduces examples of commonly used directory operation functions such as is_dir, rd_dir, mkdir and so on in the PHP tutorial.
*/
function dir_writeable($dir) //Custom function extension function to create a writable directory
{
if(!is_dir($dir)) //If the given parameter is not a directory
{
@mkdir($dir,0777); //Create directory
echo "Directory".$dir."Created successfully!";
}
}
dir_writeable("test"); //Call a custom function to create a test directory
/*
Executing this code will create a directory named: test in the current directory, and will output:
Directory test was created successfully
*/
$dir="test"; //Define directory
if(rmdir($dir)) //If the directory is successfully deleted
{
echo "Directory".$dir." was successfully deleted!"; //Output content
}
else
{
echo "An error occurred while deleting directory ".$dir."!";
}
//
$path="test.txt"; //Define path
echo $path; //
before output processing
$realpath=realpath($path); //Normalize the output of the specified absolute path
echo "
";
echo $realpath //Output the processed result
//Look at a complete practical 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 directory
}
if(is_dir($dir))
{
If($fp=@fopen("$dir/test.txt",'w')) //Open the file in the specified path in writing mode and create it if it does not exist
{
@unlink("$dir/test.txt"); //Delete file
$writeable=1; // Define the return value to be true
}
else
{
$writeable=0; // Define the return value to be false
}
}
Return $writeable; //Return value
} //End of custom function