Home >Backend Development >PHP Tutorial >PHP obtains the directory under the specified directory and creates the file under the obtained directory, multi-platform_PHP tutorial

PHP obtains the directory under the specified directory and creates the file under the obtained directory, multi-platform_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:25:47867browse

Copy code The code is as follows:

//Get the directory name of the specified folder
function get_dir_name($dir_path,$file)
{
$dirpath = $dir_path;
$dir = scandir($dirpath);
foreach ($dir as $key=>$value)
{
if ( is_dir($dirpath.'/'.$value) && $value != '.' && $value != '..')
{
//echo $dirpath.'/'.$value. '/'.$file;
//Generate a config.php file in the directory. Of course, this file can be defined by yourself
if (!file_exists($dirpath.'/'.$value.'/' .$file))
{
$fo = fopen($dirpath.'/'.$value.'/'.$file,'xb+'); //While here, I tried to use w+, the result failed,
//Under windows, I created it successfully, please pay attention! All suggestions are to use xb+, compatible with multiple platforms
chmod($file, "0777");
fwrite( $ fo,'i is a zongzi ,here is config file!') or die('Configuration file creation failed! Please check whether you have operating permissions for this directory and file!');
fclose($fo);
}
$arr[] = $value;
}
}
return $arr;
}

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/324053.htmlTechArticleCopy the code as follows: //Get the directory name of the specified folder function get_dir_name($dir_path,$file) { $dirpath = $dir_path; $dir = scandir($dirpath); foreach ($dir as $key=$va...
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