How to detect and create directories in a php loop

WBOY
Release: 2016-07-25 09:04:49
Original
1074 people have browsed it
  1. // Loop to create directories
  2. function mk_dir($dir, $mode = 0755)
  3. {
  4. if (is_dir($dir) || @mkdir($dir,$mode)) return true;
  5. if (!mk_dir(dirname($dir),$mode)) return false;
  6. return @mkdir($dir,$mode);
  7. }
Copy code

Method 2:

  1. $filepath = "test/upload/2010/image.gif";

  2. createDir(dirname($filepath));
  3. //Then you can move_uploaded_file !

  4. /*

  5. * Function: Loop to detect and create folders
  6. * Parameters: $path Folder path
  7. * Return:
  8. */
  9. function createDir($path){
  10. if (! file_exists($path)){
  11. createDir(dirname($path));
  12. mkdir($path, 0777);
  13. }
  14. }
  15. ?>

Copy code


source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template