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);
}
Copy the code The code is as follows:
php
$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.