zoukankan      html  css  js  c++  java
  • php--------文件夹文件拷贝和复制

    php开发中常常对文件进行操作,文件夹和文件的拷贝,复制等。

    /**
     * 文件夹文件拷贝
     *
     * @param string $src 来源文件夹
     * @param string $dst 目的地文件夹
     * @return bool
     */
    function dir_copy($src = '', $dst = '')
    {
        if (empty($src) || empty($dst))
        {
            return false;
        }
     
        $dir = opendir($src);
        dir_mkdir($dst);
        while (false !== ($file = readdir($dir)))
        {
            if (($file != '.') && ($file != '..'))
            {
                if (is_dir($src . '/' . $file))
                {
                    dir_copy($src . '/' . $file, $dst . '/' . $file);
                }
                else
                {
                    copy($src . '/' . $file, $dst . '/' . $file);
                }
            }
        }
        closedir($dir);
     
        return true;
    }
     
    /**
     * 创建文件夹
     *
     * @param string $path 文件夹路径
     * @param int $mode 访问权限
     * @param bool $recursive 是否递归创建
     * @return bool
     */
    function dir_mkdir($path = '', $mode = 0777, $recursive = true)
    {
        clearstatcache();
        if (!is_dir($path))
        {
            mkdir($path, $mode, $recursive);
            return chmod($path, $mode);
        }
     
        return true;
    }
  • 相关阅读:
    red and black(BFS)
    G
    D
    new word
    CSS Layout
    G
    CSS
    组合数学-母函数
    组合数学-卡特兰数
    cf1144G 将串分解成单调递增和递减子串(贪心)
  • 原文地址:https://www.cnblogs.com/zhangqie/p/8403583.html
Copyright © 2011-2022 走看看