Home >Backend Development >PHP Tutorial >PHP directory creation function that supports multiple platforms_PHP tutorial
Support multi-platform PHP directory creation function We can specify which directory to create a directory in. /Get the directory name of the specified folder
Support multi-platform PHP tutorial directory creation function
We can specify which directory to create a directory in.
/Get the directory name of the specified folder
2 function get_dir_name($dir_path,$file)
3 {
4 $dirpath = $dir_path;
5 $dir = scandir($dirpath);
6 foreach ($dir as $key=>$value)
7 {
8 if (is_dir($dirpath.'/'.$value) && $value != '.' && $value != '..')
9 {
10 //echo $dirpath.'/'.$value.'/'.$file; 11 // Generate a config.php file in the directory, of course this file can be defined by yourself
12 if (!file_exists($dirpath.'/'.$value.'/'.$file))
13 14 $fo = fopen($dirpath.'/'.$value.'/'.$file,'xb+'); //When I was here, I tried to use w+ before, but it failed,
15 // Under Windows, I have successfully created it, please pay attention! All suggestions are recommended to use XB+, compatible with multiple platforms
16 chmod($file,"0777");
17 fwrite( $fo,'i is a zongzi ,here is config file!') or die('Failed to create the configuration file! Please check whether you have the operating permissions for this directory and file!');
18 fclose($fo); 19 }
20 $arr[] = $value;
21 }
22 23 return $arr;
24 }