四虎精品视频-四虎精品成人免费网站-四虎黄色网-四虎国产视频-国产免费91-国产蜜臀97一区二区三区

php目錄操作實例代碼

復(fù)制代碼 代碼如下:
<?php
    /**
    * listdir
    */
    header("content-type:text/html;charset=utf-8");

    $dirname = "./final/factapplication";

    function listdir($dirname) {
        $ds = opendir($dirname);
        while (false !== ($file = readdir($ds))) {
            $path = $dirname.'/'.$file;
            if ($file != '.' && $file != '..') {
                if (is_dir($path)) {
                    listdir($path);
                } else {
                    echo $file."<br>";
                }
            }
        }
        closedir($ds);
    }
    listdir($dirname);

核心:遞歸的經(jīng)典應(yīng)用,以及文件和目錄的基本操作。

復(fù)制代碼 代碼如下:
<?php
    /**
    * copydir
    */

    $srcdir = "../fileupload";
    $dstdir = "b";

    function copydir($srcdir, $dstdir) {
        mkdir($dstdir);
        $ds = opendir($srcdir);

        while (false !== ($file = readdir($ds))) {
            $path = $srcdir."/".$file;
            $dstpath = $dstdir."/".$file;
            if ($file != "." && $file != "..") {
                if (is_dir($path)) {
                    copydir($path, $dstpath);
                } else {
                    copy($path, $dstpath);
                }
            }
        }
        closedir($ds);

    }

    copydir($srcdir, $dstdir);

核心:copy函數(shù)。
復(fù)制代碼 代碼如下:
<?php
    /**
    * deldir
    */

    $dirname = 'a';

    function deldir($dirname) {
        $ds = opendir($dirname);

        while (false !== ($file = readdir($ds))) {
            $path = $dirname.'/'.$file;
            if($file != '.' && $file != '..') {
                if (is_dir($path)) {
                    deldir($path);
                } else {
                    unlink($path);
                }
            }
        }
        closedir($ds);

        return rmdir($dirname);
    }

    deldir($dirname);

核心:注意unlink刪除的是帶path的file。

復(fù)制代碼 代碼如下:
<?php
    /**
    * dirsize
    */

    $dirname = "a";

    function dirsize($dirname) {
        static $tot;
        $ds = opendir($dirname);
        while (false !== ($file = readdir($ds))) {
            $path = $dirname.'/'.$file;
            if ($file != '.' && $file != '..') {
                if(is_dir($path)) {
                    dirsize($path);
                } else {
                    $tot = $tot + filesize($path);
                }
            }
        }
        return $tot;
        closedir($ds);
    }

    echo dirsize($dirname);

核心:通過判斷$tot在哪里返回,理解遞歸函數(shù)。

php技術(shù)php目錄操作實例代碼,轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 韩国三级播放| 全国房价| 李顺载| 下女们| 叠影危情| 土壤动植物的乐园教学反思| 性的张力短片集| russian institute| 黛博拉·安沃尔| 熊乃瑾个人资料| 朱莉安妮全集在线观看免费| 电影壮志凌云| 黄光亮| 电影不扣钮的女孩| 飞龙猛将演员表| a friend in need中文翻译| 国产调教视频丨vk| 日记| 程慕轩| ab变频器中文说明书| 张天爱演过的三级| 新三国高清在线观看| 索玛花开 电视剧| 那些花儿吉他谱原版| 病毒感染血常规有什么异常| 武林外传豆瓣| 荒岛大逃亡电影| 男同性恋| 黄金广场| 山西少儿频道| 爱情三选一| 中长发图片2024最新款女| 首映式| 哈基米| 被骗了打什么电话求助| 陶飞霏| 杨英格| 高钧贤| 电影壮志凌云女版满天星法版在线看 | 美少女战士变身| 性感美女动漫|