Home >Backend Development >PHP Tutorial >PHP loop detects whether the directory exists and creates it (loop to create directory)_PHP tutorial

PHP loop detects whether the directory exists and creates it (loop to create directory)_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:32:041103browse

Loop creation directory method
This will generate the image.gif directory

Copy the code The code is as follows:

$ filepath = "test/upload/2010/image.gif";
mk_dir($filepath);
// Loop to create directories
function mk_dir($dir, $mode = 0755)
{
if (is_dir($dir) || @mkdir($dir,$mode)) return true;
if (!mk_dir(dirname($dir),$mode)) return false;
return @ mkdir($dir,$mode);
}

Second method:
Copy code The code is as follows:

$filepath = "test/upload/2010/image.gif";
createDir(dirname($filepath));
//Next You can move_uploaded_file!

/*
* Function: Loop to detect and create folders
* Parameters: $path Folder path
* Return:
*/
function createDir($path ){
if (!file_exists($path)){
createDir(dirname($path));
mkdir($path, 0777);
}
}
? >

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/322877.htmlTechArticleLoop directory creation method This will generate the image.gif directory copy code The code is as follows: $filepath = "test/upload/ 2010/image.gif"; mk_dir($filepath); // Loop to create directory function mk_di...
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