public function actionUploadDict() { $sougouDir = Yii::$app->params['sougouDictDir']; $dictFiles = array(); if (file_exists($sougouDir)) { if (is_writable($sougouDir)) { $oDir = dir($sougouDir); while (($file = $oDir->read()) !== false) { if (strcasecmp($file, '.') != 0 && strcasecmp($file, '..') != 0) { $filename = $sougouDir . '/' . $file; if (is_dir($filename)) { $subDir = dir($filename); while (($subFile = $subDir->read()) !== false) { if (strcasecmp($subFile, '.') != 0 && strcasecmp($subFile, '..') != 0) { $dictFiles[$file][] = $subFile; } } } } } } else { exit('目录不可写'); } } $count = count($dictFiles); $page = isset($_REQUEST['page']) ? $_REQUEST['page'] ? $_REQUEST['page'] : 1 : 1; $pageSize = 10; $start = ($page - 1) * $pageSize; $pager = new \yii\data\Pagination(array('defaultPageSize' => $pageSize, 'totalCount' => $count)); if ($page > $pager->getPageCount() && $page != 1) { exit('超过最大页数'); } $data = array(); if ($count) { $sArr = array_slice($dictFiles, $start, $pageSize, true); foreach ($sArr as $time => $value) { if (!empty($value)) { foreach ($value as $key => $val) { if (preg_match('/\\.scel/', $val)) { $file = $sougouDir . '/' . $time . '/' . $val; $data[$time][$key] = array('filename' => mb_convert_encoding($val, 'UTF-8', 'GBK,GB2312'), 'filesize' => \app\common\XUtils::file_size_format(filesize($file)), 'filetype' => filetype($file), 'filetime' => date('Y-m-d H:i:s', filemtime($file))); } } } } } if (Yii::$app->request->isPost) { exit(json_encode(array('data' => $data, 'pager' => \yii\widgets\LinkPager::widget(['pagination' => $pager, 'prevPageLabel' => '上一页', 'nextPageLabel' => '下一页'])))); } return $this->render('uploaddict', array('data' => $data, 'pager' => $pager)); }