php directory manipulation functions (delete, create, determine)

Source: Internet
Author: User
Keywords Network programming PHP tutorial
Tags create custom delete directory directory operation directory operations echo examples

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

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.