PHP Directory operation function (delete, create, judge) _php tutorial

Source: Internet
Author: User
Tags function examples
This article is mainly introduced in the PHP directory operation function Is_dir,rd_dir,mkdir and other commonly used directory operation function examples.

This article is mainly introduced in the PHP Tutorial directory operation function Is_dir,rd_dir,mkdir and other commonly used directory operation function examples.
*/
function dir_writeable ($dir)//Custom functions extension function, create writable directory
{
if (!is_dir ($dir))//If the given parameter is not a directory
{
@mkdir ($dir, 0777); Create a Directory
echo "Catalog". $dir. " Build Success! ";
}
}
Dir_writeable ("test"); Call a custom function to build the test directory
/*
Executing this code will create a directory named: Test in the current directory, and will output:
Catalog Test established successfully
*/

$dir = "Test"; Define Directory
if (RmDir ($dir))//If the directory is deleted successfully
{
echo "Catalog". $dir. " was successfully deleted! "; Output content
}
Else
{
echo "Delete directory". $dir. " , there is an error! ";
}

//

$path = "Test.txt"; Define Path
echo $path; Before the output is processed
$realpath =realpath ($path); Normalize the output with the specified absolute path
echo "
";
echo $realpath//Results after output processing

Take a look at the finishing example

function dir_writeable ($dir)//Build custom Function Extension function
{
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 ')//write to open the file under the specified path, if it does not exist, create
{
@fclose ($FP); Close file handle
@unlink ("$dir/test.txt"); deleting files
$writeable = 1; Defines the return value as True
}
Else
{
$writeable = 0; Defines the return value as False
}
}
return $writeable; return value
}//Custom Function end

http://www.bkjia.com/PHPjc/631715.html www.bkjia.com true http://www.bkjia.com/PHPjc/631715.html techarticle This article is mainly introduced in the PHP directory operation function Is_dir,rd_dir,mkdir and other commonly used directory operation function examples. This article is mainly introduced in PHP Tutorial directory operation function Is_dir,rd_di ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.