Home  >  Article  >  Backend Development  >  PHP在获取指定目录下的目录,在获取的目录下面再创建文件,多平台_PHP教程

PHP在获取指定目录下的目录,在获取的目录下面再创建文件,多平台_PHP教程

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

复制代码 代码如下:

//取得指定文件夹的目录名称
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;
//在目录下生成一个config.php文件,当然这个文件可以自己定义了
if (!file_exists($dirpath.'/'.$value.'/'.$file))
{
$fo = fopen($dirpath.'/'.$value.'/'.$file,'xb+'); //在这里的时候,我之前尝试用w+,结果失败,
//在windows 下,我有创建成功,请注意了!所有建议用xb+,兼容多平台
chmod($file,"0777");
fwrite( $fo,'i is a zongzi ,here is config file!') or die('配置文件创建失败!请检查是否有此目录和文件的操作权限!');
fclose($fo);
}
$arr[] = $value;
}
}
return $arr;
}

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/324053.htmlTechArticle复制代码 代码如下: //取得指定文件夹的目录名称 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