Home > Backend Development > PHP Tutorial > do i really have nothing lyrics php loop detect if directory exists and create loop create directory

do i really have nothing lyrics php loop detect if directory exists and create loop create directory

WBOY
Release: 2016-07-29 08:44:06
Original
1206 people have browsed it

Loop creation 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 the code The code is as follows:


$filepath = "test/upload/2010/image.gif";
createDir(dirname($filepath));
//Then 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);
}
}
?>

The above introduces whether I really have nothing to lose lyrics. PHP loop detects whether the directory exists and creates a loop to create the directory, including the content of whether I really have nothing to do with lyrics. I hope it will be helpful to friends who are interested in PHP tutorials.

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