Heim  >  Artikel  >  php教程  >  支持多平台的php目录创建函数

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

WBOY
WBOYOriginal
2016-06-13 10:03:471201Durchsuche

支持多平台的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         }
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn