public static function files($fileKey) { try { if (empty($fileKey)) { throw new Exception("fileKey为空"); } $query = new DocFile(_QUERY_ALL); $query->fileKey = $fileKey; $query->inModule = "company"; return DocFile::query($query); } catch (Exception $e) { throw $e; } }
<?php $bannerHtml = ""; $bannerBtn = ""; $query = new DocFile(_QUERY_ALL); $query->fileKey = $showHomeBanner ? "company_banner" : "company_banner2"; $query->inModule = "company"; $banners = DocFile::query($query); if (empty($banners)) { $banner = new DocFile(_NONE); $banner->savedPath = "images/banner.png"; $banners = array($banner); } if ($showHomeBanner) { //首页Banner foreach ($banners as $i => $banner) { $bannerHtml .= sprintf("<li class='%s'><a href='%s'><img src='%s' alt='%s' class='home_banner_img'></a></li>", $bannerHtml == "" ? "" : "hidden", empty($banner->fileUrl) ? "index.php" : $banner->fileUrl, str_replace("../", "", $banner->savedPath), empty($banner->fileDesc) ? Company::content("site_desc", false) : $banner->fileDesc); $bannerBtn .= sprintf("<li %s>%u</li>", $i == 0 ? "class='selected'" : "", $i + 1); } $bannerHtml = sprintf("<ul>%s</ul>", $bannerHtml); $bannerBtn = sprintf("<ul>%s</ul>", $bannerBtn); } else { //内页Banner $banner = $banners[0]; $bannerHtml = sprintf("<a href='%s'><img src='%s' alt='%s' class='inner_banner_img'></a>", empty($banner->fileUrl) ? "index.php" : $banner->fileUrl, str_replace("../", "", $banner->savedPath), empty($banner->fileDesc) ? Company::content("site_desc", false) : $banner->fileDesc); } $hot_search = ""; $query = new Company(_QUERY_ALL); $query->companyKey = "hot_search"; $hots = Company::query($query); if (!empty($hots)) {
try { Tool::logger(__METHOD__, __LINE__, sprintf("上传文件[%s]", $upload_dir . $fileName), _LOG_INFOR); if (move_uploaded_file($flUpload["tmp_name"], "../" . $upload_dir . $fileName) === false) { $is_upload = false; $result = "上传移动临时文件出错"; throw new Exception($result); } else { // 删除可能的历史记录 Tool::logger(__METHOD__, __LINE__, "删除可能的历史记录", _LOG_INFOR); $notDel = array("company_banner", "case_image", "company_links", "material_file"); //不需要删除旧数据 $docFile = new DocFile(_QUERY_ALL); $docFile->fileKey = $fileKey; $docFile->inModule = $module; if (!in_array($fileKey, $notDel)) { $data = DocFile::query($docFile); if (!empty($data)) { foreach ($data as $file) { if (is_file("../" . $file->savedPath)) { @unlink("../" . $file->savedPath); } DocFile::delete($file); } } } $docFile->showedName = $oldName; $docFile->extName = $extName; $docFile->savedPath = $upload_dir . $fileName; $docFile->fileDesc = $fileDesc; $docFile->fileUrl = $fileUrl; $docFile->fileSort = $fileSort;
//读取文件 if ($dataType == "file" || $dataType == "file_count") { $fileKey = strtolower(isset($_REQUEST["fileKey"]) ? $_REQUEST["fileKey"] : ""); $savedPath = strtolower(isset($_REQUEST["savedPath"]) ? $_REQUEST["savedPath"] : ""); try { $query = new DocFile($querySize); $query->inModule = $module; $query->fileKey = $fileKey; if (!empty($savedPath)) { $query->savedPath = $savedPath; } $query->isPaging = $isPaging; $query->curPage = $curPage; $listJson = "[]"; if ($dataType == "file") { $data = DocFile::query($query); if (!empty($data)) { $listJson = json_encode($data, JSON_UNESCAPED_UNICODE); } Tool::logger(__METHOD__, __LINE__, sprintf("查询文件Json: %s", $listJson), _LOG_INFOR); } else { if ($dataType == "file_count") { $listJson = DocFile::rcount($query); Tool::logger(__METHOD__, __LINE__, sprintf("查询文件总数: %s", $listJson), _LOG_INFOR); } } echo "{\"status\":\"true\", \"data\": " . $listJson . "}"; } catch (Exception $e) { echo "{\"status\":\"false\", \"data\": \"" . $e->getMessage() . "\"}"; Tool::logger(__METHOD__, __LINE__, sprintf("数据查询失败: %s", $e->getMessage()), _LOG_ERROR); }