The PHP loop detects the existence of the directory and creates the of loop to create the directory
- 2020-03-31 21:27:50
- OfStack
Loop through the directory method
This will generate the image.gif directory
$filepath = "test/upload/2010/image.gif";
mk_dir($filepath);
//Circular directory creation
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);
}
The second method:
<?php
$filepath = "test/upload/2010/image.gif";
createDir(dirname($filepath));
//Now we can move_uploaded_file!
function createDir($path){
if (!file_exists($path)){
createDir(dirname($path));
mkdir($path, 0777);
}
}
?>