Changeset 16764
- Timestamp:
- 2007/11/08 23:02:23 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/feature-module-update/data/class/util/SC_Utils.php
r16710 r16764 21 21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 22 */ 23 23 24 24 /** 25 25 * 各種ユーティリティクラス. … … 1385 1385 } 1386 1386 } 1387 1387 1388 1388 // ディレクトリを再帰的に生成する 1389 1389 function sfMakeDir($path) { … … 1407 1407 GC_Utils::gfPrintLog("mkdir $dir"); 1408 1408 } 1409 } 1409 } 1410 1410 } 1411 1411 } 1412 1412 return; 1413 1413 } 1414 1414 1415 1415 // ディレクトリ以下のファイルを再帰的にコピー 1416 1416 function sfCopyDir($src, $des, $mess = "", $override = false){ … … 1476 1476 $ret = SC_Utils::sfDelFile($del_file); 1477 1477 } 1478 1478 1479 1479 if(!$ret){ 1480 1480 return $ret; 1481 1481 } 1482 1482 } 1483 1483 1484 1484 // 閉じる 1485 1485 closedir($dh); 1486 1486 1487 1487 // フォルダを削除 1488 1488 return rmdir($dir); … … 1535 1535 flush(); 1536 1536 1537 ob_ end_flush();1537 ob_flush(); 1538 1538 ob_start(); 1539 1539 … … 1639 1639 } 1640 1640 } 1641 1642 /* 1641 1642 /* 1643 1643 * 関数名:sfGetFileList() 1644 1644 * 説明 :指定パス配下のディレクトリ取得 … … 1648 1648 $arrFileList = array(); 1649 1649 $arrDirList = array(); 1650 1650 1651 1651 if (is_dir($dir)) { 1652 if ($dh = opendir($dir)) { 1652 if ($dh = opendir($dir)) { 1653 1653 $cnt = 0; 1654 1654 // 行末の/を取り除く … … 1657 1657 // アルファベットと数字でソート 1658 1658 natcasesort($arrDir); 1659 foreach($arrDir as $file) { 1659 foreach($arrDir as $file) { 1660 1660 // ./ と ../を除くファイルのみを取得 1661 1661 if($file != "." && $file != "..") { 1662 1662 1663 1663 $path = $dir."/".$file; 1664 1664 // SELECT内の見た目を整えるため指定文字数で切る 1665 $file_name = SC_Utils::sfCutString($file, FILE_NAME_LEN); 1665 $file_name = SC_Utils::sfCutString($file, FILE_NAME_LEN); 1666 1666 $file_size = SC_Utils::sfCutString(SC_Utils::sfGetDirSize($path), FILE_NAME_LEN); 1667 1667 $file_time = date("Y/m/d", filemtime($path)); 1668 1668 1669 1669 // ディレクトリとファイルで格納配列を変える 1670 1670 if(is_dir($path)) { … … 1672 1672 $arrDirList[$cnt]['file_path'] = $path; 1673 1673 $arrDirList[$cnt]['file_size'] = $file_size; 1674 $arrDirList[$cnt]['file_time'] = $file_time; 1674 $arrDirList[$cnt]['file_time'] = $file_time; 1675 1675 $arrDirList[$cnt]['is_dir'] = true; 1676 1676 } else { … … 1678 1678 $arrFileList[$cnt]['file_path'] = $path; 1679 1679 $arrFileList[$cnt]['file_size'] = $file_size; 1680 $arrFileList[$cnt]['file_time'] = $file_time; 1680 $arrFileList[$cnt]['file_time'] = $file_time; 1681 1681 $arrFileList[$cnt]['is_dir'] = false; 1682 1682 } … … 1684 1684 } 1685 1685 } 1686 closedir($dh); 1686 closedir($dh); 1687 1687 } 1688 1688 } 1689 1689 1690 1690 // フォルダを先頭にしてマージ 1691 1691 return array_merge($arrDirList, $arrFileList); 1692 1692 } 1693 1694 /* 1693 1694 /* 1695 1695 * 関数名:sfGetDirSize() 1696 1696 * 説明 :指定したディレクトリのバイト数を取得 … … 1701 1701 // ディレクトリの場合下層ファイルの総量を取得 1702 1702 if (is_dir($dir)) { 1703 $handle = opendir($dir); 1703 $handle = opendir($dir); 1704 1704 while ($file = readdir($handle)) { 1705 1705 // 行末の/を取り除く 1706 1706 $dir = ereg_replace("/$", "", $dir); 1707 1707 $path = $dir."/".$file; 1708 if ($file != '..' && $file != '.' && !is_dir($path)) { 1709 $bytes += filesize($path); 1708 if ($file != '..' && $file != '.' && !is_dir($path)) { 1709 $bytes += filesize($path); 1710 1710 } else if (is_dir($path) && $file != '..' && $file != '.') { 1711 1711 // 下層ファイルのバイト数を取得する為、再帰的に呼び出す。 1712 $bytes += SC_Utils::sfGetDirSize($path); 1713 } 1714 } 1712 $bytes += SC_Utils::sfGetDirSize($path); 1713 } 1714 } 1715 1715 } else { 1716 1716 // ファイルの場合 … … 1720 1720 // ディレクトリ(ファイル)が存在しない場合は0byteを返す 1721 1721 if($bytes == "") $bytes = 0; 1722 1722 1723 1723 return $bytes; 1724 1724 } 1725 1726 /* 1725 1726 /* 1727 1727 * 関数名:sfDeleteDir() 1728 1728 * 説明 :指定したディレクトリを削除 … … 1754 1754 // ファイル削除 1755 1755 $arrResult[0]['result'] = @unlink("$dir"); 1756 $arrResult[0]['file_name'] = "$dir"; 1756 $arrResult[0]['file_name'] = "$dir"; 1757 1757 } 1758 1758 } 1759 1759 1760 1760 return $arrResult; 1761 1761 } 1762 1763 /* 1762 1763 /* 1764 1764 * 関数名:sfGetFileTree() 1765 1765 * 説明 :ツリー生成用配列取得(javascriptに渡す用) … … 1768 1768 */ 1769 1769 function sfGetFileTree($dir, $tree_status) { 1770 1770 1771 1771 $cnt = 0; 1772 1772 $arrTree = array(); 1773 1773 $default_rank = count(split('/', $dir)); 1774 1774 1775 1775 // 文末の/を取り除く 1776 $dir = ereg_replace("/$", "", $dir); 1776 $dir = ereg_replace("/$", "", $dir); 1777 1777 // 最上位層を格納(user_data/) 1778 1778 if(sfDirChildExists($dir)) { 1779 1779 $arrTree[$cnt]['type'] = "_parent"; 1780 1780 } else { 1781 $arrTree[$cnt]['type'] = "_child"; 1781 $arrTree[$cnt]['type'] = "_child"; 1782 1782 } 1783 1783 $arrTree[$cnt]['path'] = $dir; … … 1790 1790 $arrTree[$cnt]['open'] = true; 1791 1791 } 1792 $cnt++; 1793 1792 $cnt++; 1793 1794 1794 sfGetFileTreeSub($dir, $default_rank, $cnt, $arrTree, $tree_status); 1795 1795 1796 1796 return $arrTree; 1797 1797 } 1798 1799 /* 1798 1799 /* 1800 1800 * 関数名:sfGetFileTree() 1801 1801 * 説明 :ツリー生成用配列取得(javascriptに渡す用) … … 1806 1806 */ 1807 1807 function sfGetFileTreeSub($dir, $default_rank, &$cnt, &$arrTree, $tree_status) { 1808 1808 1809 1809 if(file_exists($dir)) { 1810 1810 if ($handle = opendir("$dir")) { 1811 while (false !== ($item = readdir($handle))) $arrDir[] = $item; 1811 while (false !== ($item = readdir($handle))) $arrDir[] = $item; 1812 1812 // アルファベットと数字でソート 1813 1813 natcasesort($arrDir); … … 1823 1823 $arrTree[$cnt]['type'] = "_parent"; 1824 1824 } else { 1825 $arrTree[$cnt]['type'] = "_child"; 1825 $arrTree[$cnt]['type'] = "_child"; 1826 1826 } 1827 1827 1828 1828 // 階層を割り出す 1829 1829 $arrCnt = split('/', $path); … … 1843 1843 } 1844 1844 } 1845 1846 /* 1845 1846 /* 1847 1847 * 関数名:sfDirChildExists() 1848 1848 * 説明 :指定したディレクトリ配下にファイルがあるか … … 1852 1852 if(file_exists($dir)) { 1853 1853 if (is_dir($dir)) { 1854 $handle = opendir($dir); 1854 $handle = opendir($dir); 1855 1855 while ($file = readdir($handle)) { 1856 1856 // 行末の/を取り除く 1857 1857 $dir = ereg_replace("/$", "", $dir); 1858 1858 $path = $dir."/".$file; 1859 if ($file != '..' && $file != '.' && is_dir($path)) { 1859 if ($file != '..' && $file != '.' && is_dir($path)) { 1860 1860 return true; 1861 } 1862 } 1861 } 1862 } 1863 1863 } 1864 1864 } 1865 1865 1866 1866 return false; 1867 1867 } 1868 1869 /* 1868 1869 /* 1870 1870 * 関数名:lfIsFileOpen() 1871 1871 * 説明 :指定したファイルが前回開かれた状態にあったかチェック … … 1878 1878 return true; 1879 1879 } 1880 1880 1881 1881 return false; 1882 1882 } 1883 1884 /* 1883 1884 /* 1885 1885 * 関数名:sfDownloadFile() 1886 1886 * 引数1 :ファイルパス … … 1895 1895 echo (sfReadFile($file)); 1896 1896 } 1897 1898 /* 1897 1898 /* 1899 1899 * 関数名:sfCreateFile() 1900 1900 * 引数1 :ファイルパス … … 1909 1909 $ret = @mkdir($file); 1910 1910 } 1911 1911 1912 1912 return $ret; 1913 1913 } 1914 1915 /* 1914 1915 /* 1916 1916 * 関数名:sfReadFile() 1917 1917 * 引数1 :ファイルパス 1918 1918 * 説明 :ファイル読込 1919 1919 */ 1920 function sfReadFile($filename) { 1921 $str = ""; 1922 // バイナリモードでオープン 1923 $fp = @fopen($filename, "rb" ); 1924 //ファイル内容を全て変数に読み込む 1925 if($fp) { 1926 $str = @fread($fp, filesize($filename)+1); 1927 } 1920 function sfReadFile($filename) { 1921 $str = ""; 1922 // バイナリモードでオープン 1923 $fp = @fopen($filename, "rb" ); 1924 //ファイル内容を全て変数に読み込む 1925 if($fp) { 1926 $str = @fread($fp, filesize($filename)+1); 1927 } 1928 1928 @fclose($fp); 1929 1930 return $str; 1929 1930 return $str; 1931 1931 } 1932 1932 1933 1933 /** 1934 1934 * 出力バッファをフラッシュし, バッファリングを開始する. … … 1941 1941 ob_start(); 1942 1942 } 1943 1943 1944 1944 /* デバッグ用 ------------------------------------------------------------------------------------------------*/ 1945 1945 function sfPrintR($obj) {
Note: See TracChangeset
for help on using the changeset viewer.
