Home  >  Article  >  Backend Development  >  PHP loop creation directory example sharing (php creates multi-level directories)_PHP tutorial

PHP loop creation directory example sharing (php creates multi-level directories)_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:37:05765browse

Copy code The code is as follows:

function mk_dir($dir, $mod = 0777)
{
if(!is_dir($dir) || mkdir($dir, $mod))
 {
 if(!mk_dir(dirname($dir, $mod)))
  {
  return false ;
  }
 }
  return mkdir($dir, $mod);
}

Principle: Just keep trying to create the upper directory, and so on

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/736810.htmlTechArticleCopy the code as follows: function mk_dir($dir, $mod = 0777) { if(!is_dir($dir ) || mkdir($dir, $mod)) { if(!mk_dir(dirname($dir, $mod))) { return false; } } return mkdir($dir, $mo...
Statement:
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