<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace ModStart\Core\Util; use ModStart\Core\Exception\BizException; class FileUtil { public static function mime($BTuN4) { goto Mzekn; Mzekn: static $F5ds6 = array('png' => 'image/png', 'gif' => 'image/gif', 'jpg' => 'image/jpeg', 'jpeg' => 'image/jpeg'); goto SCBC9; SCBC9: $BTuN4 = strtolower($BTuN4); goto GtRTm; GtRTm: return isset($F5ds6[$BTuN4]) ? $F5ds6[$BTuN4] : null; goto M62J6; M62J6: } public static function extension($dqVT6) { goto ng93x; ng93x: $NSzyn = strtolower(pathinfo($dqVT6, PATHINFO_EXTENSION)); goto BCFD2; Ir2tS: return $NSzyn; goto Vcetz; BCFD2: $K3Ni_ = strpos($NSzyn, '?'); goto juuN9; juuN9: if (false !== $K3Ni_) { return substr($NSzyn, 0, $K3Ni_); } goto Ir2tS; Vcetz: } public static function arrayToCSVString($I_JnK) { goto rxJTB; tYTxN: return chr(239) . chr(187) . chr(191) . join('
', $BjmXw); goto FkoOV; q8QRI: foreach ($I_JnK as $Nrp0b) { goto CggM3; wVgEc: $BjmXw[] = join('', $jAgZg); goto mkFo7; JJ5Uk: foreach ($Nrp0b as $ohYVl) { $jAgZg[] = '"' . str_replace('"', '""', $ohYVl) . '",'; } goto wVgEc; CggM3: $jAgZg = array(); goto JJ5Uk; mkFo7: } goto tYTxN; rxJTB: $BjmXw = array(); goto q8QRI; FkoOV: } public static function listAllFiles($h6NRE, $cF9SB = null, &$RgydD = array(), $DRhsw = '') { goto flZ1i; flZ1i: $nmKJs = self::listFiles($h6NRE, '*|.*'); goto IdUDP; IdUDP: foreach ($nmKJs as $oU8qf) { goto c2Wvq; Kkaml: if ($oU8qf['isDir']) { self::listAllFiles($oU8qf['path'] . '/' . $oU8qf['filename'], $cF9SB, $RgydD, $DRhsw ? $DRhsw . DIRECTORY_SEPARATOR . $oU8qf['filename'] : $oU8qf['filename']); } goto KSlXD; pN686: $RgydD[] = $oU8qf; goto g1U3a; KSlXD: $oU8qf['filename'] = $DRhsw ? $DRhsw . DIRECTORY_SEPARATOR . $oU8qf['filename'] : $oU8qf['filename']; goto pN686; c2Wvq: if (null !== $cF9SB && !call_user_func($cF9SB, $oU8qf)) { continue; } goto Kkaml; g1U3a: } goto mKQU0; mKQU0: return $RgydD; goto ptmfK; ptmfK: } public static function listFiles($fHqPM, $BSl3r = '*') { goto HuuHU; xJrOF: if (is_dir($fHqPM)) { $fHqPM = rtrim($fHqPM, '/') . '/'; } goto HkTve; sigUD: usort($h6NRE, $bUEOA); goto Ta6vH; Ta6vH: return $h6NRE; goto Dig31; PXCD6: $h6NRE = array(); goto xJrOF; HuuHU: if (strpos($BSl3r, '|') !== false) { $F5wVl = explode('|', $BSl3r); } else { $F5wVl[0] = $BSl3r; } goto hydCg; HkTve: foreach ($F5wVl as $BSl3r) { $I_JnK = glob($fHqPM . $BSl3r); if ($I_JnK !== false) { foreach ($I_JnK as $oU8qf) { goto fKPYN; G8Mif: $h6NRE[$K3Ni_]['atime'] = fileatime($oU8qf); goto r34eg; DJeBm: $h6NRE[$K3Ni_]['isFile'] = is_file($oU8qf); goto MwcFP; fKPYN: $kaNJf = basename($oU8qf); goto B3l0q; BKvyx: $h6NRE[$K3Ni_]['ext'] = is_file($oU8qf) ? strtolower(substr(strrchr(basename($oU8qf), '.'), 1)) : ''; goto JpGbX; B3l0q: if ($kaNJf === '..' || $kaNJf === '.') { continue; } goto XeETP; JpGbX: $h6NRE[$K3Ni_]['isDir'] = is_dir($oU8qf); goto DJeBm; jewsp: $h6NRE[$K3Ni_]['isWritable'] = is_writable($oU8qf); goto suajB; m30Oo: $h6NRE[$K3Ni_]['pathname'] = realpath($oU8qf); goto xg8w2; xg8w2: $h6NRE[$K3Ni_]['owner'] = fileowner($oU8qf); goto uuydX; eWi1h: $h6NRE[$K3Ni_]['isReadable'] = is_readable($oU8qf); goto jewsp; NGjoZ: $h6NRE[$K3Ni_]['size'] = filesize($oU8qf); goto QzoiS; QzoiS: $h6NRE[$K3Ni_]['type'] = filetype($oU8qf); goto BKvyx; uuydX: $h6NRE[$K3Ni_]['perms'] = substr(base_convert(fileperms($oU8qf), 10, 8), -4); goto G8Mif; suajB: $K3Ni_++; goto prPi1; XeETP: $h6NRE[$K3Ni_]['filename'] = $kaNJf; goto JyJSV; r34eg: $h6NRE[$K3Ni_]['ctime'] = filectime($oU8qf); goto utr7i; MwcFP: $h6NRE[$K3Ni_]['isLink'] = is_link($oU8qf); goto eWi1h; JyJSV: $h6NRE[$K3Ni_]['path'] = dirname($oU8qf); goto m30Oo; utr7i: $h6NRE[$K3Ni_]['mtime'] = filemtime($oU8qf); goto NGjoZ; prPi1: } } } goto HEUd_; HEUd_: $bUEOA = create_function('$a,$b', '
        if( ($a["isDir"] && $b["isDir"]) || (!$a["isDir"] && !$b["isDir"]) ){
            return  $a["filename"]>$b["filename"]?1:-1;
        }else{
            if($a["isDir"]){
                return -1;
            }else if($b["isDir"]){
                return 1;
            }
            if($a["filename"]  ==  $b["filename"])  return  0;
            return  $a["filename"]>$b["filename"]?-1:1;
        }
        '); goto sigUD; hydCg: $K3Ni_ = 0; goto PXCD6; Dig31: } public static function name($dqVT6) { return strtolower(pathinfo($dqVT6, PATHINFO_BASENAME)); } public static function formatByte($sU1VT, $mZcIE = 2) { goto yM8KQ; WbTlA: $jFNql = array(' Bytes', ' KB', ' MB', ' GB', ' TB', ' PB', ' EB', ' ZB', ' YB'); goto pFwF1; pFwF1: return round($DJshY / pow(1024, $K3Ni_ = floor(log($DJshY, 1024))), $mZcIE) . $jFNql[$K3Ni_]; goto OoMWG; IYxg_: if ($DJshY == 0) { return '0 Bytes'; } goto WbTlA; yM8KQ: $DJshY = sprintf('%u', $sU1VT); goto IYxg_; OoMWG: } public static function formattedSizeToBytes($qix3p) { goto liDIr; cNEjo: $jFNql = array('b' => 0, 'kb' => 1, 'mb' => 2, 'gb' => 3, 'tb' => 4, 'k' => 1, 'm' => 2, 'g' => 3, 't' => 4); goto jj9qC; liDIr: $qix3p = strtolower($qix3p); goto mmt6m; jj9qC: $x2GR3 = isset($jFNql[$JUUur]) ? $jFNql[$JUUur] : 0; goto h39I9; mmt6m: $JUUur = preg_replace('/[^a-z]/', '', $qix3p); goto v3a28; v3a28: $tzAUI = floatval(preg_replace('/[^0-9.]/', '', $qix3p)); goto cNEjo; h39I9: return $tzAUI * pow(1024, $x2GR3); goto Ob3TU; Ob3TU: } public static function getAndEnsurePathnameFolder($dqVT6) { goto fTiuV; Y6t6i: return trim($KB0Rf, '/') . '/'; goto CbdPC; E68Q3: if (!file_exists($KB0Rf)) { @mkdir($KB0Rf, 493, true); } goto Y6t6i; fTiuV: $KB0Rf = dirname($dqVT6); goto E68Q3; CbdPC: } public static function getPathnameFilename($dqVT6, $hD2nn = true) { $lAlmj = pathinfo($dqVT6); return $hD2nn ? $lAlmj['basename'] : $lAlmj['filename']; } public static function ensureFilepathDir($dqVT6) { $h6NRE = dirname($dqVT6); if (!file_exists($h6NRE)) { @mkdir($h6NRE, 493, true); } } public static function number2dir($UFOLC, $p7a4y = 3) { goto fH6pL; h6dwU: for ($K3Ni_ = 0; $K3Ni_ < $p7a4y; $K3Ni_++) { $xJFX_[] = substr($A1q3T, $K3Ni_ * 3, 3); } goto OZbEi; XS_yP: $A1q3T = sprintf('%0' . $XJUHT . 'd', $UFOLC); goto AEIyA; AEIyA: $xJFX_ = array(); goto h6dwU; fH6pL: $XJUHT = $p7a4y * 3; goto XS_yP; OZbEi: return join('/', $xJFX_); goto siUYm; siUYm: } public static function copy($KK5Cu, $fpJ54, $rEBq6 = null, $l2aoe = null, $cF9SB = null) { goto KBIq5; PNz6V: $fpJ54 = rtrim($fpJ54, '/') . '/'; goto bditz; KBIq5: if (!file_exists($KK5Cu)) { return; } goto PpW5n; tcPPF: closedir($h6NRE); goto xPZZz; PpW5n: if (is_file($KK5Cu)) { if (!$cF9SB || call_user_func($cF9SB, $KK5Cu, $fpJ54)) { goto bPVPi; bPVPi: if (file_exists($fpJ54) && md5_file($KK5Cu) == md5_file($fpJ54)) { return; } goto Hl5_s; Hl5_s: if (null !== $rEBq6 && file_exists($fpJ54)) { @rename($fpJ54, $fpJ54 . $rEBq6); } goto CW0Ta; a3z_o: copy($KK5Cu, $fpJ54); goto hxomn; C3NOm: if ($l2aoe) { call_user_func($l2aoe, $KK5Cu, $fpJ54); } goto a3z_o; CW0Ta: if (!file_exists($h6NRE = dirname($fpJ54))) { @mkdir($h6NRE, 493, true); } goto C3NOm; hxomn: } return; } else { if (!$cF9SB || call_user_func($cF9SB, $KK5Cu, $fpJ54)) { } else { return; } } goto eV3j8; bditz: $h6NRE = opendir($KK5Cu); goto B5thn; B5thn: @mkdir($fpJ54, 493, true); goto I0Blz; I0Blz: while (false !== ($oU8qf = readdir($h6NRE))) { if ($oU8qf != '.' && $oU8qf != '..') { if (is_dir($KK5Cu . $oU8qf)) { self::copy($KK5Cu . $oU8qf . '/', $fpJ54 . $oU8qf . '/', $rEBq6, $l2aoe, $cF9SB); } else { if (!$cF9SB || call_user_func($cF9SB, $KK5Cu . $oU8qf, $fpJ54 . $oU8qf)) { goto OeY5E; e65x0: copy($KK5Cu . $oU8qf, $fpJ54 . $oU8qf); goto ymRPW; Bvj7S: if ($l2aoe) { call_user_func($l2aoe, $KK5Cu . $oU8qf, $fpJ54 . $oU8qf); } goto e65x0; w3eqc: if (null !== $rEBq6 && file_exists($fpJ54 . $oU8qf)) { @rename($fpJ54 . $oU8qf, $fpJ54 . $oU8qf . $rEBq6); } goto Bvj7S; OeY5E: if (file_exists($fpJ54 . $oU8qf) && md5_file($fpJ54 . $oU8qf) == md5_file($KK5Cu . $oU8qf)) { continue; } goto w3eqc; ymRPW: } } } } goto tcPPF; eV3j8: $KK5Cu = rtrim($KK5Cu, '/') . '/'; goto PNz6V; xPZZz: } public static function rm($h6NRE, $bZznH = true) { if (is_dir($h6NRE)) { goto EN4hD; EN4hD: $IJQWg = opendir($h6NRE); goto cOMky; cOMky: while (($oU8qf = readdir($IJQWg)) !== false) { if ($oU8qf != '.' && $oU8qf != '..') { $sdJSp = rtrim($h6NRE, '/') . '/' . $oU8qf; if (is_dir($sdJSp)) { self::rm($sdJSp, true); } else { @unlink($sdJSp); } } } goto dBCe7; dBCe7: closedir($IJQWg); goto vW7xa; vW7xa: if ($bZznH) { @rmdir($h6NRE); } goto xzB6x; xzB6x: } else { @unlink($h6NRE); } return true; } public static function savePathToLocalTemp($ceAjB, $NSzyn = '') { goto HpD7p; HpD7p: $M037Q = public_path('temp/' . md5($ceAjB) . (starts_with($NSzyn, '.') ? $NSzyn : '.' . $NSzyn)); goto dX9ex; dX9ex: if (file_exists($M037Q)) { return $M037Q; } goto qbYkl; qbYkl: if (StrUtil::startWith($ceAjB, 'http://') || StrUtil::startWith($ceAjB, 'https://') || StrUtil::startWith($ceAjB, '//')) { goto tL7V4; tL7V4: if (StrUtil::startWith($ceAjB, '//')) { $ceAjB = 'http://' . $ceAjB; } goto nW1JA; nW1JA: $S2FiA = CurlUtil::getRaw($ceAjB); goto Z_Ar9; r2yC6: file_put_contents($M037Q, $S2FiA); goto ZrLvv; cwa9F: @mkdir(public_path('temp')); goto r2yC6; Z_Ar9: if (empty($S2FiA)) { return null; } goto cwa9F; ZrLvv: } else { if (StrUtil::startWith($ceAjB, '/')) { $ceAjB = substr($ceAjB, 1); } $M037Q = public_path($ceAjB); } goto mvMKV; mvMKV: if (!file_exists($M037Q)) { return null; } goto T_uKw; T_uKw: return $M037Q; goto Hrasc; Hrasc: } public static function generateLocalTempPath($NSzyn = 'tmp') { for ($K3Ni_ = 0; $K3Ni_ < 10; $K3Ni_++) { $M037Q = public_path('temp/' . RandomUtil::lowerString(32) . '.' . $NSzyn); if (!file_exists($M037Q)) { return $M037Q; } } BizException::throws('FileUtil generateLocalTempPath error'); } }