Home  >  Article  >  Backend Development  >  PHP loop to create multi-level directory example

PHP loop to create multi-level directory example

WBOY
WBOYOriginal
2016-07-25 08:54:061150browse
  1. function mk_dir($dir, $mod = 0777)
  2. {
  3.  if(!is_dir($dir) || mkdir($dir, $mod))
  4.  {
  5.   if(!mk_dir (dirname($dir, $mod)))
  6.    {
  7.    return false;
  8.   }
  9.   }
  10.   return mkdir($dir, $mod);
  11. }
Copy code

Principle: Keep trying to create upper-level directories, So on and so forth.



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