php文件操作
php文件操作 这里讲的文件操作主要是讲php获取文件的主要信息,判断文件的性质,获取文件名和目录名等哦。下面看三个实例php教程文件操作
这里讲的文件操作主要是讲php获取文件的主要信息,判断文件的性质,获取文件名和目录名等哦。下面看三个实例
*/
//获取文件的主要信息。
$file = "data.txt";if(is_dir($file))
{
echo "文件 $file 是个目录";
echo "<br/>";
}
else
{
echo "文件 $file 不是目录";
echo "<br/>";
}if(is_file($file))
{
echo "文件 $file 是一个普通文件";
echo "<br/>";
}if(is_readable($file))
{
echo "文件 $file 是可读的";
echo "<br/>";
}
else
{
echo "文件 $file 是不可读的";
echo "<br/>";
}if(is_writeable($file))
{
echo "文件 $file 是可写的";
echo "<br/>";
}
else
{
echo "文件 $file 是不可写的";
echo "<br/>";
}
//判断文件的性质。
$path = "/home/prog/php/sayhello.php";$file_name = basename($path);
$dir_name = dirname($path);echo "完整路径:".$path;
echo "<hr>";
echo "<br/>";echo "其中目录名为:".$dir_name;
echo "<br/>";
echo "其中文件名为:".$file_name;
echo "<br/>";
//获取文件名和目录名。
$file = "data.txt";
$dir = "info/newdata";if(file_exists($file))
{
echo "当前目录中,文件".$file."存在";
echo "<br/>";
}
else
{
echo "当前目录中,文件".$file."不存在";
echo "<br/>";
}
echo "<br/>";
echo "<hr>";
echo "<br/>";if(file_exists($dir))
{
echo "当前目录下,目录".$dir."存在";
echo "<br/>";
}
else
{
echo "当前目录下,目录".$dir."不存在";
echo "<br/>";
}
PHP之友评论