Determine if a folder exists and does not exist create the folder

Source: Internet
Author: User

1. Determine if there is
One:

if (@mkdir ("/img", 0700) {echo "OK";} Else{echo "Error";} There is output "OK", there is no output "error"

Two:

if (Is_dir ("/img")) {echo "OK";} Else{echo "Error";} There is output "OK", there is no output "error"

if (Is_dir ("img")) {echo "OK";} Else{echo "Error";} There is output "OK", there is no output "error"

2. When the folder does not exist, try to create it

One:

if (@mkdir ("path", 0700) {echo "OK";} Else{echo "Error";} Create successful output "OK", create failed or existing output "error"

if (@mkdir ("Aaa/ss", 0700) {echo "OK";} Else{echo "Error";} Create successful output "OK", create failed or existing output "error"

Two: A way to create a folder

function Mkdirs ($dir, $mode = 0777)

{

if (Is_dir ($dir) | | @mkdir ($DIR, $mode)) return TRUE;

if (!mkdirs (DirName ($dir), $mode)) return FALSE;

Return @mkdir ($dir, $mode);

}

Three. Determine if it exists and does not exist create:

$temp =true;

if (!is_dir (". /yitaoimg ")) {if (@mkdir (". /yitaoimg ", 0700)) {}else{$temp =false;}}

If there is no Yitaoimg folder under the IF ($temp) {}else{echo "relative path, and you do not have permission to create it, you may try to create it manually";}

3. An existing folder tries to delete it (an empty folder with appropriate permissions)

$path = "path";
if ([email protected] ($path))
{
Echo ("Delete failed! You may not have permissions, or delete the empty folder ");
}else{echo "Delete succeeded";}


This article is from "Buffy Rain Blog" blog, please be sure to keep this source http://bafeiyu.blog.51cto.com/5401101/1602459

Determine if a folder exists and does not exist create the folder

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.