Source for file rainFileManager.php

Documentation is available at rainFileManager.php

  1. <?
  2.  
  3. /**  
  4.  * Ã·ºÎ ÆÄÀÏ °ü¸® ¹× ±âŸ »ý¼ºµÈ ÀӽàÆÄÀÏ °ü¸®
  5.  * @package com.rain
  6.  * @version 1.0
  7.  * @author http://cafen.net (outmind@cafen.net)
  8. */
  9. class rainFileManager {
  10.  
  11.     /**  
  12.      * °ü¸®ÇÒ ÆÄÀÏ °æ·Î
  13.     *
  14.     * @var String 
  15.     */
  16.     var $base_file = "";
  17.  
  18.     /**  
  19.      * È¯°æ ÆÄÀÏ °æ·Î
  20.     *
  21.     * @var String 
  22.     */
  23.     var $base_conf = "";
  24.  
  25.     /**  
  26.      * ±âº» ÀÛ¾÷ °ø°£
  27.     *
  28.     * @var String 
  29.     */
  30.     var $base_root = "";
  31.  
  32.     /**  
  33.      * ÀӽàÆÄÀÏÀÇ ÀÛ¾÷°ø°£
  34.     *
  35.     * @var String 
  36.     */
  37.     var $base_cashed = "";
  38.     
  39.     /**  
  40.      * »ý¼ºÀÚ
  41.      *
  42.      * @param  String  °ü¸®ÇÒ ÆÄÀϸí
  43.     */
  44.     function rainFileManager($fileName){
  45.         $this->base_file = $fileName;
  46.         if (rainUtil::isMovie($this->base_file)) 
  47.             $this->base_conf = "movie/" $this->base_file . ".ini";
  48.         else if (rainUtil::isImage($this->base_file)) 
  49.             $this->base_conf = "thumb/" $this->base_file . ".ini";
  50.         else 
  51.             $this->base_conf = "thumb/" $this->base_file . ".ini";
  52.         $this->base_root = rainUtil::getConf("path_uploads");
  53.     }
  54.  
  55.     /**  
  56.      * °ü·Ã ÆÄÀÏ Ãß°¡
  57.      *
  58.      * @param  String  Ãß°¡ÇÒ °ü·Ã ÆÄÀÏ
  59.     */
  60.     function add($fileName{
  61.         if (
  62.             rainUtil::checkDir($this->base_root$this->base_conf&& 
  63.             $handle @fopen($this->base_root . $this->base_conf"a")
  64.         {
  65.             fwrite($handle ,basename($fileName"#");
  66.             fclose($handle);
  67.         }
  68.     }
  69.  
  70.     /**  
  71.      * Àӽ࿵¿ª Æúµå °¡Á®¿À±â
  72.      *
  73.      * @return  String Àӽÿµ¿ª Æúµå¸í
  74.     */
  75.     function getCashDir($fileName ""{
  76.         if ($fileName == "")
  77.             $fileName $this->base_file;
  78.         $cash_dir "";
  79.         if (rainUtil::isMovie($fileName)) 
  80.             $cash_dir dirname("movie/" $fileName);
  81.         else if (rainUtil::isImage($fileName)) 
  82.             $cash_dir dirname("thumb/" $fileName);
  83.         return $cash_dir;
  84.     }
  85.  
  86.     /**  
  87.      * Àӽ࿵¿ª ÆúµåÀбâ
  88.      *
  89.      * @return  Array    ÆÄÀÏÁ¤º¸
  90.     */
  91.     function readCashed({
  92.         $file_str "";
  93.         if (file_exists($this->base_root . $this->base_conf)) 
  94.             $file_str implode(''@file($this->base_root . $this->base_conf));
  95.         return explode('#',$file_str);
  96.     }
  97.  
  98.     /**  
  99.      * ÀӽàÆÄÀÏ »èÁ¦
  100.     */
  101.     function deleteJunk({
  102.         $real_path "junk/";
  103.         $base_time rainUtil::getNow(60*60*2;
  104.         if ($handle @opendir($this->base_root.$real_path)) {
  105.             while (false !== ($file @readdir($handle))) 
  106.                 $fileName $real_path $file;
  107.                 if ($file != "." && $file != ".." && !is_dir($this->base_root.$fileName&& filemtime($this->base_root.$fileName$base_time{
  108.                     $junkmanager new rainFileManager($fileName);
  109.                     $junkmanager->delete(true);
  110.                 }
  111.             }
  112.         }
  113.         closedir($handle);
  114.     }
  115.     
  116.     /**  
  117.      * ÆÄÀÏ »èÁ¦
  118.      *
  119.      * @param  Boolean  ½ÇÁ¦»èÁ¦ ¿©ºÎ(true:½ÇÁ¦»èÁ¦µÊ, false:°ü·Ã ¸ðµç ÆÄÀÏ¸í µÚ¿¡ _ À» ºÙÀÓ) false ·Î »èÁ¦µÈ °æ¿ì º¹±¸°¡´É
  120.     */
  121.     function delete($isReal false{
  122.         if ($isReal{
  123.             echo "<br>";
  124.             echo $this->base_root . $this->base_file;
  125.             if (file_exists($this->base_root . $this->base_file))
  126.                 @unlink($this->base_root . $this->base_file);
  127.             $cash_dir $this->getCashDir();
  128.             if ($cash_dir != ""{
  129.                 $fileList $this->readCashed();
  130.                 for($i 0$i count($fileList)$i++{
  131.                     if ($fileList[$i!= ""{
  132.                         $cashedName $this->base_root . $cash_dir "/" $fileList[$i];
  133.                         if (file_exists($cashedName))
  134.                             @unlink($cashedName);
  135.                     }
  136.                 }    
  137.             }
  138.             if (file_exists($this->base_root . $this->base_conf))
  139.                 @unlink($this->base_root . $this->base_conf);
  140.         else {
  141.             if (file_exists($this->base_root . $this->base_file))
  142.                 @rename($this->base_root . $this->base_file,$this->base_root . $this->base_file . '_');
  143.             $cash_dir $this->getCashDir();
  144.             if ($cash_dir != ""{
  145.                 $fileList $this->readCashed();
  146.                 for($i 0$i count($fileList)$i++{
  147.                     if ($fileList[$i!= ""{
  148.                         $cashedName $this->base_root . $cash_dir "/" $fileList[$i];
  149.                         if (file_exists($cashedName))
  150.                             @rename($cashedName$cashedName '_');
  151.                     }
  152.                 }    
  153.             }
  154.             if (file_exists($this->base_root . $this->base_conf))
  155.                 @rename($this->base_root . $this->base_conf$this->base_root . $this->base_conf . '_');
  156.         }
  157.         if (!rainUtil::find("^junk/",$this->base_file&& (rand(0,10== 0)) 
  158.             $this->deleteJunk();
  159.     }
  160.  
  161.     /**  
  162.      * ÆÄÀÏ ÀÌÀü
  163.      *
  164.      * @param  String ÀÌÀüÇÒ ÆÄÀÏ °æ·Î
  165.     */
  166.     function move($dirName{
  167.         if (rainUtil::checkDir($this->base_root$dirName)) {
  168.             $dirName dirname($dirName);
  169.             $baseName basename($this->base_file);
  170.             if (file_exists($this->base_root . $this->base_file))
  171.                 @rename($this->base_root . $this->base_file$this->base_root . $dirName "/" $baseName);
  172.             $cash_dir $this->getCashDir();
  173.             $ncash_dir $this->getCashDir($dirName "/" $baseName);
  174.             if ($cash_dir != "" && $ncash_dir != ""{
  175.                 if (rainUtil::checkDir($this->base_root$ncash_dir "/" $baseName)) {
  176.                     $fileList $this->readCashed();
  177.                     for($i 0$i count($fileList)$i++{
  178.                         if ($fileList[$i!= ""{
  179.                             $cashedName $this->base_root . $cash_dir "/" $fileList[$i];
  180.                             $ncashedName $this->base_root . $ncash_dir "/" $fileList[$i];
  181.                             if (file_exists($cashedName))
  182.                                 @rename($cashedName$ncashedName);
  183.                             else
  184.                                 rainUtil::errorLog("$cashedName$ncashedName");
  185.                         }
  186.                     }
  187.                 }
  188.             }
  189.             if (file_exists($this->base_root . $this->base_conf))
  190.                 @rename($this->base_root . $this->base_conf$this->base_root . $ncash_dir "/" $baseName ".ini");
  191.         }
  192.     }
  193.  
  194.     /**  
  195.      * ÆÄÀÏ º¹±¸ - delete(false) ·Î »èÁ¦µÈ °æ¿ì¸¸ º¹±¸µÊ
  196.     */
  197.     function restore({
  198.         if (file_exists($this->base_root . $this->base_file . "_"))
  199.             @rename($this->base_root . $this->base_file . "_"$this->base_root . $this->base_file);
  200.         if (file_exists($this->base_root . $this->base_conf . "_"))
  201.             @rename($this->base_root . $this->base_conf . "_"$this->base_root . $this->base_conf);
  202.         $cash_dir $this->getCashDir();
  203.         if ($cash_dir != ""{
  204.             $fileList $this->readCashed();
  205.             for($i 0$i count($fileList)$i++{
  206.                 if ($fileList[$i!= ""{
  207.                     $cashedName $this->base_root . $cash_dir "/" $fileList[$i];
  208.                     if (file_exists($cashedName "_"))
  209.                         @rename($cashedName "_",$cashedName);
  210.                 }
  211.             }    
  212.         }
  213.     }
  214. }
  215.  
  216. ?>

Documentation generated on Mon, 17 Mar 2008 12:17:47 +0900 by phpDocumentor 1.4.0a2 | Copyright 2005 cafen.net