最模板 - 外贸网站建设,外贸网站模板

最模板

当前位置: 首页 > 建站教程 > php教程 >

php文件操作

时间:2014-06-09 16:40来源: 作者: 点击: 次
这里讲的文件操作主要是讲php获取文件的主要信息,判断文件的性质,获取文件名和目录名等哦,下面看三个实例: */ //获取文件的主要信息。 $file = data.txt ; if ( is_dir ( $file )) { echo 文件$file是个目录

这里讲的文件操作主要是讲php获取文件的主要信息,判断文件的性质,获取文件名和目录名等哦,下面看三个实例:

  1. */ 
  2. //获取文件的主要信息。 
  3. $file = "data.txt"; 
  4. if(is_dir($file)) 
  5. { 
  6.     echo "文件 $file 是个目录"; 
  7.     echo "<br/>"; 
  8. } 
  9. else 
  10. { 
  11.     echo "文件 $file 不是目录"; 
  12.     echo "<br/>"; 
  13. } 
  14. if(is_file($file)) 
  15. { 
  16.     echo "文件 $file 是一个普通文件"; 
  17.     echo "<br/>"; 
  18. } 
  19. if(is_readable($file)) 
  20. { 
  21.     echo "文件 $file 是可读的"; 
  22.     echo "<br/>"; 
  23. } 
  24. else 
  25. { 
  26.     echo "文件 $file 是不可读的"; 
  27.     echo "<br/>"; 
  28. } 
  29. if(is_writeable($file)) 
  30. { 
  31.    echo "文件 $file 是可写的"; 
  32.    echo "<br/>"; 
  33. } 
  34. else 
  35. { 
  36.    echo "文件 $file 是不可写的"; 
  37.    echo "<br/>"; 
  38. } 
  39. //判断文件的性质。 
  40. $path = "/home/prog/php/sayhello.php"; 
  41. $file_name = basename($path); 
  42. $dir_name = dirname($path); 
  43. echo "完整路径:".$path; 
  44. echo "<hr>"; 
  45. echo "<br/>"; 
  46. echo "其中目录名为:".$dir_name; 
  47. echo "<br/>"; 
  48. echo "其中文件名为:".$file_name; 
  49. echo "<br/>"; 
  50. //获取文件名和目录名。 
  51. $file = "data.txt"; 
  52. $dir = "info/newdata"; 
  53. if(file_exists($file)) 
  54. { 
  55.     echo "当前目录中,文件".$file."存在"; 
  56.     echo "<br/>"; 
  57. } 
  58. else 
  59. { 
  60.      echo "当前目录中,文件".$file."不存在"; 
  61.      echo "<br/>"; 
  62. } 
  63. echo "<br/>"; 
  64. echo "<hr>"; 
  65. echo "<br/>"; 
  66. if(file_exists($dir)) 
  67. { 
  68.     echo "当前目录下,目录".$dir."存在"; 
  69.     echo "<br/>"; 
  70. } 
  71. else 
  72. { 
  73.      echo "当前目录下,目录".$dir."不存在"; 
  74.      echo "<br/>"; 
  75. } 
(责任编辑:admin)
------分隔线----------------------------
栏目列表
推荐内容