Home > Backend Development > PHP Tutorial > Directory operation functions in php (delete, create, judge)_PHP tutorial

Directory operation functions in php (delete, create, judge)_PHP tutorial

WBOY
Release: 2016-07-13 16:55:08
Original
1005 people have browsed it

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

http://www.bkjia.com/PHPjc/631715.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/631715.htmlTechArticleThis 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 the directory operation functions is_dir,rd_di...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template