Error in creating a folder using mkdir method in PHP-php Tutorial

Source: Internet
Author: User
When uploading an image, I want to display the image by year, month, or day based on the current date, so I have the following code {code ...} the above code is successfully tested in a local testing environment (PHP + apache + MySQL. However, when I upload code to the server, the following error is reported: Warning: mkdir () [fun... when uploading an image, I want to display the image by year, month, or day based on the current date, so I have the following code:

 

The above code is successfully tested in a local testing environment (PHP + apache + MySQL. However, when I upload code to the server, the following error will be reported:
Warning: mkdir () [function. mkdir]: open_basedir restriction in effect. file (D: \ hosting) is not within the allowed path (s): (D: \ hosting \ wwwroot \; D: \ hosting \ System \; C: \ WINDOWS \ Temp \) in D: \ hosting \ wwwroot \ obbzz_com \ htdocs \ mytest. php on line 47

What is the cause of this situation?

Reply content:

When uploading an image, I want to display the image by year, month, or day based on the current date, so I have the following code:

 

The above code is successfully tested in a local testing environment (PHP + apache + MySQL. However, when I upload code to the server, the following error will be reported:
Warning: mkdir () [function. mkdir]: open_basedir restriction in effect. file (D: \ hosting) is not within the allowed path (s): (D: \ hosting \ wwwroot \; D: \ hosting \ System \; C: \ WINDOWS \ Temp \) in D: \ hosting \ wwwroot \ obbzz_com \ htdocs \ mytest. php on line 47

What is the cause of this situation?

There is a problem where you generate multi-level directories. php cannot generate multi-level directories at a time.date("Y/m/d"), You must check whether the directory exists cyclically. if it does not exist, create another level.

Apparently, I have not read the official PHP documentation.

Http://php.net/manual/en/function.mkd...

Bool mkdir (string $ pathname [, int $ mode = 0777 [, bool $ recursive = false [, resource $ context])

The third parameter is true, similar to File. mkdirs in Java.

The following is my function, which is quite useful.

function mkdirs($dir)      {          if(!is_dir($dir))          {              if(!mkdirs(dirname($dir))){                  return false;            }              if(!mkdir($dir,0777)){                  return false;            }            chmod($dir, 0777);         }          return true;      }

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.