php源码之检测文件是否可读可写(is_writable is_readable实例)

时间:2016-08-18
本文章向大家介绍php如何判断文件是否可读可写,主要使用到php的两个函数is_writable和is_readable,需要的朋友可以参考一下本文章的源代码。

php 源码之判断文件是否可读:

Is the file readable: is_readable()

<?php
$file = "test.txt";
outputFileTestInfo( $file );
function outputFileTestInfo( $f ){
   if ( ! file_exists( $f ) ){
       print "$f does not exist<BR>";
      return;
   }
   print "$f is ".(is_readable( $f )?"":"not ")."readable<br>";
}
?>

php 源码之判断文件是否可写:

Is the file writable: is_writable()

<?php
$file = "test.txt";
outputFileTestInfo( $file );
function outputFileTestInfo( $f ){
   if ( ! file_exists( $f ) ){
       print "$f does not exist<BR>";
      return;
   }
   /* http://www.manongjc.com/article/1370.html */
   print "$f is ".(is_writable( $f )?"":"not ")."writable<br>";
}
?>