Home > php教程 > php手册 > PHP在获取指定目录下的目录,在获取的目录下面再创建文件,多平台

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

WBOY
Release: 2016-06-06 20:38:24
Original
1081 people have browsed it

PHP在获取指定目录下的目录,在获取的目录下面再创建文件,多平台,需要的朋友可以参考下。

代码如下:
//取得指定文件夹的目录名称
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;
}
Related labels:
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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template