123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694 |
- <?php
- namespace Cas\Controller\Admin\Activity;
- use Cas\Module\Lottery;
- use Cas\Dao\PlatformBulletin;
- use KIF\Core\Request;
- use Cas\Dao\LotteryEvents;
- use Cas\Controller\Admin\Controller;
- use Cas\Dao\Platform;
- use Cas\Dao\Category;
- use KIF\Core\Config;
- use Cas\Dao\BackUser as DBackUser;
- /**
- * ["活动相关" - "基础设置" ]
- * 页面: 创建活动基础设置 doPageCreate
- * 事件:操作: 创建活动基础设置 doReqCreate
- * 页面: 修改&查看 活动基础设置 doPageShow
- * 事件: 修改活动基础设置 doReqUp
- *
- * @author lihuanchun
- *
- */
- class SetBasics extends Controller {
- private $objLottery; // 活动后端
- private $operatorData;
- /**
- * 初始化
- */
- public function __construct() {
- header ( "Content-Type: text/html; charset=utf-8" );
- $this->objLottery = new Lottery ();
- $this->operatorData = $this->getUser ();
- }
- public function doDefault() {
-
- }
-
- /**
- * 页面: 创建活动 基础设置
- * 地址:http://cas.lishuy.com/?c=Admin_Activity_SetBasics&a=PageCreate&type=nnn&bigType=ssss
- * 参数:
- * type = 活动类型ID [可空]
- * bigType = 活动大类字符串
- */
- public function doPageCreate() {
- $thisType = Request::g ( 'type' ); // 获取类型
- $thisBigType = Request::g ( 'bigType' ); // 获取大类型
-
- // 获取所有活动类型
- $typeData = LotteryEvents::getType ();
-
- // 获取活动大类配置
- $bigTypeConfig = LotteryEvents::getBigTypeConfig ();
-
- // 获取所有发布列表(平台列表)
- $platformList = array ();
- $objDPlatform = new Platform ();
- $platformList = $objDPlatform->getsAll ();
-
- if (!self::isSuperadmin()) {
- $objDBackUser = new DBackUser();
- $user = $objDBackUser->get(self::getUid());
- $platfrom = $user['platfrom'];
-
- $tmpPlatformList = array();
- foreach ($platfrom as $tmpPlatformId) {
- $tmpPlatformList[] = $platformList[$tmpPlatformId];
- }
- $platformList = $tmpPlatformList;
- }
-
- // 获取是否授权配置参数配置
- $authorize = LotteryEvents::getAuthorize ();
-
- // 获取是是否在列表中显示配置
- $listDisplay = LotteryEvents::getListDisplay ();
- // 是否推荐到焦点图
- $focusDisplay = LotteryEvents::getFocusDisplay ();
- // 是否置顶
- $topDisplay = LotteryEvents::getTopDisplay ();
- $objDCategory = new Category ();
- $categoryList = $objDCategory->getsAll ();
-
- // 音乐图标位置
- $getMusicPosition = LotteryEvents::getMusicPosition ();
-
- // 导航
- $navConfig = $this->getCreatePageNav($thisType,$thisBigType);
-
-
- // 微信相关模块 不包含类型
- $weixinFormNotType = array(
- LotteryEvents::TYPE_EVENTS_OTHER,
- );
- $this->setOutput ( 'weixinFormNotType', $weixinFormNotType );
-
- // 音乐相关 不包含类型
- $musicFormNotType = array(
- LotteryEvents::TYPE_EVENTS_CUT_SCREEN,
- );
- $this->setOutput ( 'musicFormNotType', $musicFormNotType );
-
- // 切屏方向 不包含的类型
- $cutDirectionFormNotType = array(
- LotteryEvents::TYPE_EVENTS_CUT_SCREEN,
- );
- $this->setOutput ( 'cutDirectionFormNotType', $cutDirectionFormNotType );
-
- $this->tpl = 'admin/activity/page_create';
- $title = '基础设置';
- $this->setOutput('title', $title);
- $this->setOutput('menu_active', array('name' => 'quickpublish', 'item' => '')); //激活菜单
- $this->addNavMenu('活动列表');
- $this->addNavMenu($title);
-
-
- $this->setOutput ( 'navConfig', $navConfig );// 导航 显示 URL 配置
- $this->setOutput ( 'getMusicPosition', $getMusicPosition );
- $this->setOutput ( 'platformList', $platformList );
- $this->setOutput ( 'categoryList', $categoryList );// 获取所有发布列表(平台列表)
- $this->setOutput ( 'focusDisplay', $focusDisplay );
- $this->setOutput ( 'topDisplay', $topDisplay );
- $this->setOutput ( 'authorize', $authorize );
- $this->setOutput ( 'listDisplay', $listDisplay );
- $this->setOutput ( 'getMusicPosition', $getMusicPosition );
-
- $this->setOutput ( 'thisBigType', $thisBigType ); // 当前选择大类
- $this->setOutput ( 'thisType', $thisType ); // 当前选择类型
- $this->setOutput ( 'typeData', $typeData ); // 所有活动类型
- $this->setOutput ( 'bigTypeConfig', $bigTypeConfig ); // 所有活动类型
- $this->setOutput('typeDesc', $typeData[$thisType]['desc']);
- $this->setOutput('pagePublicData', $this->getPagePublicData()); // 后台管理相关数据
- }
-
- /**
- * 事件: 创建活动 基础设置
- * 请求地址:http://cas.lishuy.com/?c=Admin_Activity_SetBasics&a=ReqCreate
- * 参数:见方法内 $info
- */
- public function doReqCreate() {
-
- $info ['type'] = Request::p ( 'type' ); // 获取所选类型
- $info ['img_url'] = Request::p('img_url'); // 活动头图 img_url 表单名称 img_url
- $info ['events_name'] = Request::p ( 'events_name' ); // 活动标题 events_name 时间戳
-
- if ($info['type'] == LotteryEvents::TYPE_EVENTS_ARTICLE) {
- $info ['begin_time'] = date('Y-m-d H:i');
- } else {
- $info ['begin_time'] = Request::p ( 'begin_time' ) ? Request::p ( 'begin_time' ) : '2025-01.01 00:00:00'; // 活动开始时间 begin_time 时间戳
- }
- $info ['begin_time'] = strtotime($info ['begin_time']);
- $info ['end_time'] = Request::p ( 'end_time' ) ? Request::p ( 'end_time' ) : '2025-01.01 00:00:00'; // 活动结束时间 end_time
- $info ['end_time'] = strtotime($info ['end_time']);
-
- $tmp_platform_ids = $_POST['platform_ids']; // 所属"列表"IDs platform_ids_str
- foreach ( $tmp_platform_ids as $platform_id ) {
-
- $info ['platform_ids'] += $platform_id;
- }
-
- $info ['weixinShare'] ['imgUrl'] = Request::p('wx_img_url'); // 分享图片 weixinShare[imgUrl] 表单名称 wx_img_url
- $info ['weixinShare'] ['title'] = Request::p ( 'weixinShare_title' ); // 分享标题 weixinShare[title]
- $info ['weixinShare'] ['content'] = Request::p ( 'weixinShare_content' ); // 分享内容 weixinShare[content]
- $info ['weixinShare'] ['jump_url'] = Request::p ( 'weixinShare_jump_url' ); // 分享后跳转地址 weixinShare[jump_url]
- $info ['authorize'] = Request::p ( 'authorize' ); // 是否需要登录 authorize
- $info ['list_display'] = Request::p ( 'list_display' ); // 是否在列表中出现
- $info ['top_display'] = Request::p ( 'top_display' );
- $info ['focus_display'] = Request::p ( 'focus_display' );
- $info ['category_id'] = Request::p ( 'category_id' );
-
-
- $info ['participation_user_num'] = Request::p ( 'participation_user_num' ); // 每天用户参与次数 participation_user_num
- $info ['participation_ip_num'] = Request::p ( 'participation_ip_num' ); // 允许每天IP参与次数 participation_ip_num
- $info ['participation_user_all_num'] = Request::p ( 'participation_user_all_num' ); // 允许用户参与次数 participation_user_all_num
- $info ['winning_user_num'] = Request::p ( 'winning_user_num' ); // 允许用户获奖次数 winning_user_num
-
- $info['cut_fx'] = Request::p('cut_fx'); // 切屏方向
- $info ['music_url'] = Request::p('music_url'); // 获取背景音乐 music_url 表单名称:music_url
- $info ['operator_uid'] = $this->operatorData['uid'];// 创建人UID
-
- $info ['other_url'] = Request::p ( 'other_url' ); // 跳转地址
-
- $info ['music_position'] = Request::p ( 'music_position' ); // 音乐图标位置 music_position
-
- $info['loading_bg_color'] = Request::p('loading_bg_color');
- $info['loading_text_color'] = Request::p('loading_text_color');
-
- $info ['setPageType'] = 'Basics';
-
- // 执行添加方法
- $events_id = $this->objLottery->addLotteryEvents ( $info );
-
- if (! $events_id) {
- $this->ajax_fail_exit('基础设置失败');
- }
-
- $objPlatform = new Platform();
- $formData = $objPlatform -> getsAll();
-
- $eventData = $this->objLottery->getOneLotteryEvents($events_id);
-
- foreach ( $tmp_platform_ids as $platform_id ) {
- $url = $this->objLottery ->getEventsUrl($info ['type'], $eventData['create_time'],$formData[$platform_id]['url']);
- $this->createImgCodeUrl($url);
- }
-
- // 更具不同活动 大类型 跳转 到不同的地址
- $bigTypeConfig = LotteryEvents::getBigTypeConfig ();
- if(in_array($info['type'], $bigTypeConfig['Event'])){
- $redirect_url = Request::schemeDomain () . "/?c=Admin_Activity_SetInteractive&a=PageShow&events_id={$events_id}";
- }else{
- $redirect_url = Request::schemeDomain () . "/?c=Admin_Activity_SetPage&a=PageShow&events_id={$events_id}";
- }
-
- if($info['type'] == LotteryEvents::TYPE_EVENTS_OTHER){
- $redirect_url = Request::schemeDomain () . "/?c=Admin_Activity_DeliveryChannels&a=PageList&events_id={$events_id}";
- }
-
-
- $this->ajax_success_exit($redirect_url);
- }
-
- /**
- * 页面: 修改&查看 活动基础设置 doPageShow
- * 地址:http://cas.lishuy.com/?c=Admin_Activity_SetBasics&a=PageShow&events_id=nnn
- * 参数:events_id 活动ID
- */
- public function doPageShow() {
-
- $events_id = Request::g('events_id');
- $eventData =$this->objLottery->getOneLotteryEvents($events_id);
-
- $typeData = LotteryEvents::getType ();
- $bigTypeConfig = LotteryEvents::getBigTypeConfig ();
-
- $platformList = array ();
- $objDPlatform = new Platform ();
- $platformList = $objDPlatform->getsAll ();
-
- if (!self::isSuperadmin()) {
- $objDBackUser = new DBackUser();
- $user = $objDBackUser->get(self::getUid());
- $platfrom = $user['platfrom'];
-
- $tmpPlatformList = array();
- foreach ($platfrom as $tmpPlatformId) {
- $tmpPlatformList[] = $platformList[$tmpPlatformId];
- }
- $platformList = $tmpPlatformList;
- }
-
- $authorize = LotteryEvents::getAuthorize ();
-
- // 获取是是否在列表中显示配置
- $listDisplay = LotteryEvents::getListDisplay ();
- // 是否推荐到焦点图
- $focusDisplay = LotteryEvents::getFocusDisplay ();
- // 是否置顶
- $topDisplay = LotteryEvents::getTopDisplay ();
- $objDCategory = new Category ();
- $categoryList = $objDCategory->getsAll ();
-
- $getMusicPosition = LotteryEvents::getMusicPosition ();
-
-
- $navConfig = $this->getUpPageNav($events_id, 'Basics');
-
-
- // 微信相关模块 不包含类型
- $weixinFormNotType = array(
- LotteryEvents::TYPE_EVENTS_OTHER,
- );
- $this->setOutput ( 'weixinFormNotType', $weixinFormNotType );
-
- // 音乐相关 不包含类型
- $musicFormNotType = array(
- LotteryEvents::TYPE_EVENTS_CUT_SCREEN,
- );
- $this->setOutput ( 'musicFormNotType', $musicFormNotType );
-
- // 切屏方向 不包含的类型
- $cutDirectionFormNotType = array(
- LotteryEvents::TYPE_EVENTS_CUT_SCREEN,
- );
- $this->setOutput ( 'cutDirectionFormNotType', $cutDirectionFormNotType );
-
- // 发货状态 不包含的类型
- $deliveryFormNotType = array(
- LotteryEvents::TYPE_EVENTS_CUT_SCREEN,
- LotteryEvents::TYPE_EVENTS_ARTICLE,
- LotteryEvents::TYPE_EVENTS_OTHER,
- LotteryEvents::TYPE_EVENTS_CODE,
- LotteryEvents::TYPE_EVENTS_INVITATION,
- LotteryEvents::TYPE_EVENTS_VOTE,
- );
- $this->setOutput ( 'deliveryFormNotType', $deliveryFormNotType );
-
- $deliveryDesc = LotteryEvents::getDeliveryType (); // 发货状态
- if(!$eventData['delivery']){
- $eventData['delivery'] = LotteryEvents::DELIVERY_FALSE;
- }
- $this->setOutput ( 'deliveryDesc', $deliveryDesc );
-
-
- $this->tpl = 'admin/activity/page_show';
- $title = '基础设置';
- $this->setOutput('title', $title);
- $this->setOutput('menu_active', array('name' => 'mypublish', 'item' => '')); //激活菜单
- $this->addNavMenu('活动列表');
- $this->addNavMenu($title);
-
- $objDPlatform = new Platform();
- $platFormData = $objDPlatform -> getsAll();
- # 获取当前活动都添加哪些 列表
- # 返回列表IDs
- $platFormIds = array();
- foreach($platFormData as $key => $data){
- if($eventData['platform_ids']&$key){
- $platFormIds[$key] = $key;
- }
- }
-
-
- $this->setOutput('displayDesc', LotteryEvents::getDisplay());
-
- $this->setOutput ( 'navConfig', $navConfig ); // 导航显示 URL 配置
- $this->setOutput ( 'getMusicPosition', $getMusicPosition );// 音乐图标位置
- $this->setOutput ( 'platformList', $platformList );// 获取所有发布列表(平台列表)
- $this->setOutput ( 'categoryList', $categoryList );// 获取所有发布列表(平台列表)
- $this->setOutput ( 'listDisplay', $listDisplay ); // 获取是否在列表中显示
- $this->setOutput ( 'focusDisplay', $focusDisplay );
- $this->setOutput ( 'topDisplay', $topDisplay );
- $this->setOutput ( 'authorize', $authorize );// 获取是否登录配置参数配置
- $this->setOutput ( 'typeData', $typeData ); // 所有活动类型
- $this->setOutput ( 'thisType', $eventData['type'] ); // 所有活动类型
- $this->setOutput ( 'bigTypeConfig', $bigTypeConfig ); // 所有活动类型
- $this->setOutput ( 'eventData', $eventData ); // 当前活动详情
- $this->setOutput('platFormIds', $platFormIds);
- $this->setOutput('pagePublicData', $this->getPagePublicData($events_id)); // 后台管理相关数据
-
- }
-
- /**
- * 事件: 修改活动基础设置 doReqUp
- * 地址:http://cas.lishuy.com/?c=Admin_Activity_SetBasics&a=PageShow&events_id=nnn
- * 参数:见方法内
- */
- public function doReqUp() {
- $events_id = Request::p('events_id');
-
- $info ['img_url'] = Request::p('img_url'); // 活动头图 img_url 表单名称 img_url
- // $tmpImgData = $this->loadImg ( 'img_url' );
- // if (is_array ( $tmpImgData )) {
- // $info ['img_url'] = $tmpImgData ['url'] [0];
- // }
- $info ['events_name'] = Request::p ( 'events_name' ); // 活动标题 events_name 时间戳
- $info ['begin_time'] = Request::p ( 'begin_time' ) ? Request::p ( 'begin_time' ) : '2025-01.01 00:00:00'; // 活动开始时间 begin_time 时间戳
- $info ['begin_time'] = strtotime($info ['begin_time']);
- $info ['end_time'] = Request::p ( 'end_time' ) ? Request::p ( 'end_time' ) : '2025-01.01 00:00:00'; // 活动结束时间 end_time
- $info ['end_time'] = strtotime($info ['end_time']);
-
- /*
- $tmp_platform_ids = $_POST['platform_ids'];
-
- foreach ( $tmp_platform_ids as $platform_id ) {
- $info ['platform_ids'] += $platform_id;
- }
- */
-
- $info ['weixinShare'] ['imgUrl'] = Request::p('wx_img_url'); // 分享图片 weixinShare[imgUrl] 表单名称 wx_img_url
- // $tmpImgData = $this->loadImg ( 'wx_img_url' );
- // if (is_array ( $tmpImgData )) {
- // $info ['weixinShare'] ['imgUrl'] = $tmpImgData ['url'] [0];
- // }
- $info ['weixinShare'] ['title'] = Request::p ( 'weixinShare_title' ); // 分享标题 weixinShare[title]
- $info ['weixinShare'] ['content'] = Request::p ( 'weixinShare_content' ); // 分享内容 weixinShare[content]
- $info ['weixinShare'] ['jump_url'] = Request::p ( 'weixinShare_jump_url' ); // 分享后跳转地址 weixinShare[jump_url]
- $info ['authorize'] = Request::p ( 'authorize' ); // 是否需要登录 authorize
- $info ['list_display'] = Request::p ( 'list_display' ); // 是否在列表中出现
- $info ['top_display'] = Request::p ( 'top_display' );
- $info ['focus_display'] = Request::p ( 'focus_display' );
- $info ['category_id'] = Request::p ( 'category_id' );
- $info ['delivery'] = Request::p ( 'delivery' ); // 是否发货
-
-
- $info ['participation_user_num'] = Request::p ( 'participation_user_num' ); // 每天用户参与次数 participation_user_num
- $info ['participation_ip_num'] = Request::p ( 'participation_ip_num' ); // 允许每天IP参与次数 participation_ip_num
- $info ['participation_user_all_num'] = Request::p ( 'participation_user_all_num' ); // 允许用户参与次数 participation_user_all_num
- $info ['winning_user_num'] = Request::p ( 'winning_user_num' ); // 允许用户获奖次数 winning_user_num
-
- $info['cut_fx'] = Request::p('cut_fx'); // 切屏方向
- $info ['music_url'] = Request::p('music_url'); // 获取背景音乐 music_url 表单名称:music_url
-
- $info['loading_bg_color'] = Request::p('loading_bg_color');
- $info['loading_text_color'] = Request::p('loading_text_color');
-
- // $tmpMusicData = $this->loadMusic ( 'music' );
- // if (is_array ( $tmpMusicData )) {
- // $info ['music_url'] = $tmpMusicData ['url'] [0];
- // }
-
- $info ['music_position'] = Request::p ( 'music_position' ); // 音乐图标位置 music_position
-
- $display = Request::p ( 'display' );
- if($display!=null){
- $info ['display'] = $display;
- }
-
- # 修改操作
- $tmpData = $this->objLottery->upLotteryEvents($info, array('id' => $events_id));
- if(!$tmpData){
- $this->ajax_fail_exit('修改失败');
- }
- $this->setNowUpPage($events_id, 'Basics');
- $this->ajax_success_exit(Request::schemeDomain () . "/?c=Admin_Activity_SetBasics&a=PageShow&events_id={$events_id}");
- }
-
- /**
- * 上传音乐
- *
- * @param string $files_name
- */
- public function loadMusic($files_name = 'music') {
- $uploadConfig = Config::getInstance ()->get ( 'upload' );
- // 定义允许上传的文件扩展名
- $ext_arr = array (
- 'music' => array (
- 'mp3'
- )
- );
- if (! is_array ( $_FILES [$image_name] ['name'] )) {
- foreach ( $_FILES [$image_name] as $key => $data ) {
- unset ( $_FILES [$image_name] [$key] );
- $_FILES [$image_name] [$key] [] = $data;
- }
- }
- $file_url = array ();
- foreach ( $_FILES [$image_name] ['name'] as $key => $oneData ) {
- // 文件保存目录路径
- $save_path = $uploadConfig ['path'] . '/';
- $save_path = realpath ( $save_path ) . '/';
-
- // PHP上传失败
- if ($_FILES [$image_name] ['error'] [$key] != 0) {
- switch ($_FILES [$image_name] ['error'] [$key]) {
- case '1' :
- $error = '超过php.ini允许的大小。';
- break;
- case '2' :
- $error = '超过表单允许的大小。';
- break;
- case '3' :
- $error = '音乐只有部分被上传。';
- break;
- case '4' :
- $error = '请选择音乐文件。';
- break;
- case '6' :
- $error = '找不到临时目录。';
- break;
- case '7' :
- $error = '写文件到硬盘出错。';
- break;
- case '8' :
- $error = 'File upload stopped by extension。';
- break;
- case '999' :
- default :
- $error = '未知错误。';
- }
- return $error;
- }
- // 有上传文件时
- if (empty ( $_FILES ) === false) {
- // 原文件名
- $file_name = $_FILES [$image_name] ['name'] [$key];
- // 服务器上临时文件名
- $tmp_name = $_FILES [$image_name] ['tmp_name'] [$key];
- // 文件大小
- $file_size = $_FILES [$image_name] ['size'] [$key];
- // 检查文件名
- if (! $file_name) {
- return "请选择文件。";
- }
- // 检查目录
- if (@is_dir ( $save_path ) === false) {
- return "上传目录不存在。";
- }
- // 检查目录写权限
- if (@is_writable ( $save_path ) === false) {
- return "上传目录没有写权限。";
- }
- // 检查是否已上传
- if (@is_uploaded_file ( $tmp_name ) === false) {
- return "上传失败。";
- }
- // 检查目录名
- $dir_name = 'music';
- if (empty ( $ext_arr [$dir_name] )) {
- return "目录名不正确。";
- }
- // 获得文件扩展名
- $temp_arr = explode ( ".", $file_name );
- $file_ext = array_pop ( $temp_arr );
- $file_ext = trim ( $file_ext );
- $file_ext = strtolower ( $file_ext );
- // 检查扩展名
- if (in_array ( $file_ext, $ext_arr [$dir_name] ) === false) {
- return "上传文件扩展名是不允许的扩展名。\n只允许" . implode ( ",", $ext_arr [$dir_name] ) . "格式。";
- }
- // 创建文件夹
- $ymd = date ( "Ymd" );
- $ymd = date ( "Y" ) . '/' . date ( 'md' );
- // 文件保存目录URL
- $save_url = $uploadConfig ['url'] . '/';
- $new_file_name = '';
- $save_path .= $dir_name . "/" . $ymd . "/";
-
- $save_url .= $dir_name . "/" . $ymd . "/";
- if (! file_exists ( $save_path )) {
- if (! mkdir ( $save_path, 0775, true )) {
- return "创建目录失败:{$save_path}";
- }
- }
- // 新文件名
- $new_file_name = date ( "His" ) . '_' . rand ( 10000, 99999 ) . '.' . $file_ext;
- // 移动文件
- $file_path = $save_path . $new_file_name;
- // 原图上传
- if (move_uploaded_file ( $tmp_name, $file_path ) === false) {
- return "上传文件失败。";
- }
- @chmod ( $file_path, 0777 );
- $file_url [$key] = $file_path;
- }
- }
- return array (
- 'error' => 0,
- 'url' => $file_url
- );
- }
-
- /**
- * 方法:图片上传
- */
- public function loadImg($image_name = 'image') {
- $uploadConfig = Config::getInstance ()->get ( 'upload' );
- // 定义允许上传的文件扩展名
- $ext_arr = array (
- 'image' => array (
- 'gif',
- 'jpg',
- 'jpeg',
- 'png',
- 'bmp'
- )
- );
- if (! is_array ( $_FILES [$image_name] ['name'] )) {
- foreach ( $_FILES [$image_name] as $key => $data ) {
- unset ( $_FILES [$image_name] [$key] );
- $_FILES [$image_name] [$key] [] = $data;
- }
- }
- $file_url = array ();
- foreach ( $_FILES [$image_name] ['name'] as $key => $oneData ) {
- // 文件保存目录路径
- $save_path = $uploadConfig ['path'] . '/';
- $save_path = realpath ( $save_path ) . '/';
-
- // PHP上传失败
- if ($_FILES [$image_name] ['error'] [$key] != 0) {
- switch ($_FILES [$image_name] ['error'] [$key]) {
- case '1' :
- $error = '超过php.ini允许的大小。';
- break;
- case '2' :
- $error = '超过表单允许的大小。';
- break;
- case '3' :
- $error = '图片只有部分被上传。';
- break;
- case '4' :
- $error = '请选择图片。';
- break;
- case '6' :
- $error = '找不到临时目录。';
- break;
- case '7' :
- $error = '写文件到硬盘出错。';
- break;
- case '8' :
- $error = 'File upload stopped by extension。';
- break;
- case '999' :
- default :
- $error = '未知错误。';
- }
- return $error;
- }
- // 有上传文件时
- if (empty ( $_FILES ) === false) {
- // 原文件名
- $file_name = $_FILES [$image_name] ['name'] [$key];
- // 服务器上临时文件名
- $tmp_name = $_FILES [$image_name] ['tmp_name'] [$key];
- // 文件大小
- $file_size = $_FILES [$image_name] ['size'] [$key];
- // 检查文件名
- if (! $file_name) {
- return "请选择文件。";
- }
- // 检查目录
- if (@is_dir ( $save_path ) === false) {
- return "上传目录不存在。";
- }
- // 检查目录写权限
- if (@is_writable ( $save_path ) === false) {
- return "上传目录没有写权限。";
- }
- // 检查是否已上传
- if (@is_uploaded_file ( $tmp_name ) === false) {
- return "上传失败。";
- }
- // 检查目录名
- $dir_name = 'image';
- if (empty ( $ext_arr [$dir_name] )) {
- return "目录名不正确。";
- }
- // 获得文件扩展名
- $temp_arr = explode ( ".", $file_name );
- $file_ext = array_pop ( $temp_arr );
- $file_ext = trim ( $file_ext );
- $file_ext = strtolower ( $file_ext );
- // 检查扩展名
- if (in_array ( $file_ext, $ext_arr [$dir_name] ) === false) {
- return "上传文件扩展名是不允许的扩展名。\n只允许" . implode ( ",", $ext_arr [$dir_name] ) . "格式。";
- }
- // 创建文件夹
- $ymd = date ( "Ymd" );
- $ymd = date ( "Y" ) . '/' . date ( 'md' );
- // 文件保存目录URL
- $save_url = $uploadConfig ['url'] . '/';
- $new_file_name = '';
- $save_path .= $dir_name . "/" . $ymd . "/";
-
- $save_url .= $dir_name . "/" . $ymd . "/";
- if (! file_exists ( $save_path )) {
- if (! mkdir ( $save_path, 0775, true )) {
- return "创建目录失败:{$save_path}";
- }
- }
- // 新文件名
- $new_file_name = date ( "His" ) . '_' . rand ( 10000, 99999 ) . '.' . $file_ext;
- // 移动文件
- $file_path = $save_path . $new_file_name;
- // 原图上传
- if (move_uploaded_file ( $tmp_name, $file_path ) === false) {
- return "上传文件失败。";
- }
- error_reporting ( E_ALL );
- // 压缩65质量原图
- $this_basename = basename ( $file_path );
- $this_dirname = dirname ( $file_path );
- $z_file_path = $this_dirname . '/' . 'z.' . $this_basename;
- Image::transformFormat ( $file_path, $z_file_path, 'JPG' );
- @chmod ( $file_path, 0777 );
- $file_url [$key] = $save_url . 'z.' . $new_file_name;
- }
- }
- return array (
- 'error' => 0,
- 'url' => $file_url
- );
- }
- public function display() {
- return $this->render ();
- }
- }
-
|