zoukankan      html  css  js  c++  java
  • 将文件放入按上次修改时间建立的文件夹内

    用到的我感兴趣的函数:copy($source,$dest),filemtime($filename)

    代码如下:

     1 <?php
     2 /*
     3     按文件修改或创建时间将文件放入分类的文件夹
     4 */
     5 
     6 //test
     7 $path = 'file';
     8 createDeleteFile($path);
     9 
    10 //将文件复制到按修改时间建立的文件夹,并且删除原位置的文件
    11 function createDeleteFile($path)
    12 {
    13     $dir = dir($path);
    14     //while( $file = $dir->read($dir) )
    15     while( $file = $dir->read() )
    16     {
    17         if( ($file !== '.')&&($file !== '..') )
    18         {
    19             $value = $path . '/' . $file;
    20             $time = fileTime($value);
    21             $newPath = $time . '/' . $file;
    22             if( !(file_exists($time) ) )
    23             {
    24                 mkdir($time);
    25             }
    26             moveFile($value,$newPath);
    27         }
    28         
    29     }
    30 }
    31 
    32 //获取文件的修改时间,并格式化时间
    33 function fileTime($file)
    34 {
    35     return date('Y-m-d',filemtime($file));
    36 }
    37 
    38 //移动原位置的文件到新位置,并且删除原位置的文件
    39 function moveFile($path,$newPath)
    40 {
    41     if( copy($path,$newPath) )
    42     {
    43         echo $path . '移动位置成功。<br />';
    44         if( unlink($path) )
    45         {
    46             echo $path . '原位置的文件删除成功。<br />';
    47         }
    48         else
    49         {
    50             echo $path . '原位置的文件删除失败。<br />';
    51         }
    52     }
    53     else
    54     {
    55         echo $path . '移动位置失败。<br />';
    56     }
    57 }
  • 相关阅读:
    C++ string 实现大整数相加减
    HDU2489 Minimal Ratio Tree 【DFS】+【最小生成树Prim】
    Quick-Cocos2d3.2RC1在Code IDE中实现代码提示
    Codeforces 558C Amr and Chemistry
    Linux编程---进程通信
    HDU 5371 Hotaru&#39;s problem(Manacher算法+贪心)
    微社区
    创业忌讳
    微信公众平台开发(82) 天气预报
    天气预报接口
  • 原文地址:https://www.cnblogs.com/chuganghong/p/3062367.html
Copyright © 2011-2022 走看看