i漂泊

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 3601|回复: 0

移动文件夹文件到其他地方

[复制链接]
TA的礼物信息
  • 收到:0
  • 送出:2
发表于 2014-3-17 13:16:46 | 显示全部楼层 |阅读模式
  1. FileUtil::moveDir('source/plugin/mini_tel/function/','source/class/block/tel');
复制代码
  1. /**
  2.      * 移动文件夹
  3.      *
  4.      * @param string $oldDir
  5.      * @param string $aimDir
  6.      * @param boolean $overWrite 该参数控制是否覆盖原文件
  7.      * @return boolean
  8.      */
  9.     function moveDir($oldDir, $aimDir, $overWrite = false) {
  10.         $aimDir = str_replace('', '/', $aimDir);
  11.         $aimDir = substr($aimDir, -1) == '/' ? $aimDir : $aimDir . '/';
  12.         $oldDir = str_replace('', '/', $oldDir);
  13.         $oldDir = substr($oldDir, -1) == '/' ? $oldDir : $oldDir . '/';
  14.         if (!is_dir($oldDir)) {
  15.             return false;
  16.         }
  17.         if (!file_exists($aimDir)) {
  18.             FileUtil::createDir($aimDir);
  19.         }
  20.         @$dirHandle = opendir($oldDir);
  21.         if (!$dirHandle) {
  22.             return false;
  23.         }
  24.         while (false !== ($file = readdir($dirHandle))) {
  25.             if ($file == '.' || $file == '..') {
  26.                 continue;
  27.             }
  28.             if (!is_dir($oldDir . $file)) {
  29.                 FileUtil::moveFile($oldDir . $file, $aimDir . $file, $overWrite);
  30.             } else {
  31.                 FileUtil::moveDir($oldDir . $file, $aimDir . $file, $overWrite);
  32.             }
  33.         }
  34.         closedir($dirHandle);
  35.         return rmdir($oldDir);
  36.     }

  37.     /**
  38.      * 移动文件
  39.      *
  40.      * @param string $fileUrl
  41.      * @param string $aimUrl
  42.      * @param boolean $overWrite 该参数控制是否覆盖原文件
  43.      * @return boolean
  44.      */
  45.     function moveFile($fileUrl, $aimUrl, $overWrite = false) {
  46.         if (!file_exists($fileUrl)) {
  47.             return false;
  48.         }
  49.         if (file_exists($aimUrl) && $overWrite = false) {
  50.             return false;
  51.         } elseif (file_exists($aimUrl) && $overWrite = true) {
  52.             FileUtil::unlinkFile($aimUrl);
  53.         }
  54.         $aimDir = dirname($aimUrl);
  55.         FileUtil::createDir($aimDir);
  56.         rename($fileUrl, $aimUrl);
  57.         return true;
  58.     }
复制代码
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|手机版|IPiaoBo Inc. ( 渝ICP备17002826号 )

GMT+8, 2024-5-5 08:35 , Processed in 0.078605 second(s), 46 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表