Home >Backend Development >PHP Tutorial >put your head on my shoulder PHP obtains the directory under the specified directory and creates a file under the obtained directory. Multi-platform

put your head on my shoulder PHP obtains the directory under the specified directory and creates a file under the obtained directory. Multi-platform

WBOY
WBOYOriginal
2016-07-29 08:46:231141browse

Copy the 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+'); //In Here, I tried to use w+ before, but the result failed.
//Under windows, I created 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('Failed to create configuration file! Please check whether you have the operating permissions for this directory and file!');
fclose($fo);
}
$arr[] = $value;
}
}
return $arr;
}

The above introduces how put your head on my shoulder PHP obtains the directory in the specified directory, and then creates the file under the obtained directory. It is multi-platform, including the content of put your head on my shoulder. I hope you are interested in PHP tutorials. Friends help.

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