Home > php教程 > php手册 > 支持多平台的php目录创建函数

支持多平台的php目录创建函数

WBOY
Release: 2016-06-13 10:03:47
Original
1265 people have browsed it

支持多平台的php目录创建函数 我们可以指定在那个目录下创建目录哦。 /取得指定文件夹的目录名称

支持多平台的php教程目录创建函数
我们可以指定在那个目录下创建目录哦。
/取得指定文件夹的目录名称

 2         function get_dir_name($dir_path,$file)
 3         {
 4             $dirpath = $dir_path;
 5             $dir = scandir($dirpath);
 6             foreach ($dir as $key=>$value)
 7             {
 8                 if (is_dir($dirpath.'/'.$value) && $value != '.' && $value != '..')
 9                 {
10                     //echo $dirpath.'/'.$value.'/'.$file;                   
11                     //在目录下生成一个config.php文件,当然这个文件可以自己定义了
12                     if (!file_exists($dirpath.'/'.$value.'/'.$file))
13                     {                                               
14                         $fo = fopen($dirpath.'/'.$value.'/'.$file,'xb+');    //在这里的时候,我之前尝试用w+,结果失败,
15                         //在windows 下,我有创建成功,请注意了!所有建议用xb+,兼容多平台
16                         chmod($file,"0777");
17                         fwrite( $fo,'i is a zongzi ,here is config file!') or die('配置文件创建失败!请检查是否有此目录和文件的操作权限!');
18                         fclose($fo);                                                                       
19                     }
20                     $arr[] = $value;
21                 }
22             }       
23             return $arr;
24         }
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