public function index() { global $_FANWE; clearTempImage(); include template('page/index_index'); display(); }
/** * 清除当前2小时以前的临时图片 * @param string $dir 目录路径 * @return void */ function clearTempImage($path = '') { global $_FANWE; if ($path == '') { $_FANWE['clear_image_count'] = 0; } $max_time = mktime(date('H') - 2, 0, 0, date('m'), date('d'), date('Y')) - date('Z'); $basepath = FANWE_ROOT . 'public/upload/temp/'; $paths = array(); if ($path != '') { $currentpath = str_replace($basepath, '', $path); $paths = explode('/', $currentpath); $year = (int) $paths[0]; $month = isset($paths[1]) ? (int) $paths[1] : 1; $day = isset($paths[2]) ? (int) $paths[2] : 1; $hours = isset($paths[3]) ? (int) $paths[3] : 0; $day_time = mktime($hours, 0, 0, $month, $day, $year) - date('Z'); if ($max_time <= $day_time) { return; } $currentpath .= '/'; } else { $currentpath = ''; } $dir = $basepath . $currentpath; $directory = dir($dir); while ($entry = @$directory->read()) { if ($_FANWE['clear_image_count'] >= 50) { break; } if ($entry != '.' && $entry != '..') { $filename = $dir . $entry; if (is_dir($filename)) { clearTempImage($filename); @rmdir($filename); } if (is_file($filename)) { removeFile($filename); $_FANWE['clear_image_count']++; } } } $directory->close(); }