Discuz教程网

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

[复制链接]
authicon dly 发表于 2011-9-3 19:05:34 | 显示全部楼层 |阅读模式
代码如下:

  1. //取得指定文件夹的目录名称
  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. }
复制代码








上一篇:PHP源码之explode使用说明
下一篇:PHP中获取远程客户端的真实ip地址的方法
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

1314学习网 ( 浙ICP备10214163号 )

GMT+8, 2025-5-2 20:07

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表