영원한사랑

#!/usr/bin/php
<?php

function myallfile($dir, $ext = '')
{
        $file_arr = array();
        if (is_dir($dir))
        {
                if ($dh = opendir($dir))
                {
                        while (($file = readdir($dh)) !== false)
                        {
                                $type = filetype($dir . $file);

                                if($type == 'file')
                                {
                                        if($ext != '')
                                        {
                                                $ext = strtolower($ext);
                                                $temp = explode('.',$file);
                                                if(strtolower($temp[count($temp)-1]) == $ext) $file_arr[] = $dir.$file;
                                        }
                                        else    $file_arr[] = $dir.$file;
                                }
                                else if($type == 'dir' && ($file != '.' && $file != '..'))
                                {

                                        $temp = myallfile($dir.$file.'/', $ext);
                                        if(is_array($temp))
                                        {
                                                $file_arr = array_merge($file_arr, $temp);
                                        }
                                }
                        }
                        closedir($dh);
                }
                return $file_arr;
        }
        return 0;
}
function rename_filename($str)
{
        $dir    = dirname($str);
        $oldname = basename($str);
        $newname = iconv("euc-kr", "utf-8", $oldname);
        if ($oldname != $newname)
        {
                rename("$dir/$oldname", "$dir/$newname");

                echo "$dir/$oldname";
                echo " ";
                echo "$dir/$newname";
                echo "\n";
        }
}

$path_root = '/data1/webhome/';//홈페이지 경로
$path = 'webdata/oldimage/File1/';//홈페이지 경로 아래 파일리스트 가져올 디렉토리
$php_arr = myallfile($path_root.$path);

for($i = 0 ; $i < count($php_arr) ; $i++)
{
        rename_filename($php_arr[$i]);
}
?>