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

WBOY
Release: 2016-07-21 15:25:47
Original
844 people have browsed it

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...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!