php文件目录操作

 opendir.php

<?php
$base_dir = "filelist/";
$fso  = opendir($base_dir);
echo $base_dir."<hr/>"  ;
while($flist=readdir($fso)){
echo $flist."<br/>" ;
}
closedir($fso)
?>

mkdir.php

<?php
$base_dir = "test/";
if(!file_exists($base_dir)){
$fso = mkdir($base_dir);
echo "success";
}
else{
echo "文件夹已存在";
}
?>

rm.dir

<?php
$base_dir = "test/";
if(file_exists($base_dir)){
$fso = rmdir($base_dir);
echo "success";
}
else{
echo "文件夹不存在";
}
?>

file_exists.php

<?php
$file = "test.txt";
if (file_exists($file) == false) {
        die('文件不存在');
}
else{
$data = file_get_contents($file);
echo htmlentities($data);


        $fso = fopen($file, 'r');
        $data = fread($fso, filesize($file));
  echo $data;
        fclose($fso);
}
?>

write_able.php

<?php
$file = 'test.txt';
if (is_writable($file) == false) {
        die("我是鸡毛,我不能");
}

$file = 'test.txt';
if (is_writable($file) == false) {
        die('我是鸡毛,我不能');
}
$data = '我是可鄙,我想要';
file_put_contents ($file, $data);
$f = fopen($file, 'w');
fwrite($f, $data);
fclose($f);
?>

fileown.php

<?php
$file = 'test.txt';
if (is_readable($file) == false) {
        die('文件不存在或者无法读取');
} else {
        echo '存在';
}
?>

attribute.php

<?php
$file = 'test.txt';
echo date('r', filemtime($file))."<br/>";
echo date('r', fileatime($file))."<br/>";
echo date('r', filectime($file))."<br/>";

$file = 'test.txt';
$perms = substr(sprintf('%o', fileperms($file)), -4);
echo $perms;

$filename = 'test.txt';
echo $filename . ': ' . filesize($filename) . ' bytes';

$file = 'test.txt';
$perms = stat($file);
var_dump($perms);
?>

copy.php

<?php
$file = 'test.txt';
$newfile = 'o.txt'; # 这个文件父文件夹必须能写
if (file_exists($file) == false) {
        die ('小样没上线,无法复制');
}
$result = copy($file, $newfile);
if ($result == true) {
        echo '复制记忆ok';
}
?>

delfile.php

<?php
$file = 'o.txt';
$result = @unlink ($file);
if ($result == true) {
        echo '蚊子赶走了';
} else {
        echo '无法赶走';
}
?>

    A+
发布日期:2013年12月06日  所属分类:未分类

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: