SetBasics.class.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694
  1. <?php
  2. namespace Cas\Controller\Admin\Activity;
  3. use Cas\Module\Lottery;
  4. use Cas\Dao\PlatformBulletin;
  5. use KIF\Core\Request;
  6. use Cas\Dao\LotteryEvents;
  7. use Cas\Controller\Admin\Controller;
  8. use Cas\Dao\Platform;
  9. use Cas\Dao\Category;
  10. use KIF\Core\Config;
  11. use Cas\Dao\BackUser as DBackUser;
  12. /**
  13. * ["活动相关" - "基础设置" ]
  14. * 页面: 创建活动基础设置 doPageCreate
  15. * 事件:操作: 创建活动基础设置 doReqCreate
  16. * 页面: 修改&查看 活动基础设置 doPageShow
  17. * 事件: 修改活动基础设置 doReqUp
  18. *
  19. * @author lihuanchun 
  20. *  
  21. */
  22. class SetBasics extends Controller {
  23. private $objLottery; // 活动后端
  24. private $operatorData;
  25. /**
  26. *  初始化
  27. */
  28. public function __construct() {
  29. header ( "Content-Type: text/html; charset=utf-8" );
  30. $this->objLottery = new Lottery ();
  31. $this->operatorData = $this->getUser ();
  32. }
  33. public function doDefault() {
  34. }
  35. /**
  36. * 页面: 创建活动 基础设置
  37. * 地址:http://cas.lishuy.com/?c=Admin_Activity_SetBasics&a=PageCreate&type=nnn&bigType=ssss
  38. * 参数:
  39. * type = 活动类型ID [可空]
  40. * bigType = 活动大类字符串
  41. */
  42. public function doPageCreate() {
  43. $thisType = Request::g ( 'type' ); // 获取类型
  44. $thisBigType = Request::g ( 'bigType' ); // 获取大类型
  45. // 获取所有活动类型
  46. $typeData = LotteryEvents::getType ();
  47. // 获取活动大类配置
  48. $bigTypeConfig = LotteryEvents::getBigTypeConfig ();
  49. // 获取所有发布列表(平台列表)
  50. $platformList = array ();
  51. $objDPlatform = new Platform ();
  52. $platformList = $objDPlatform->getsAll ();
  53. if (!self::isSuperadmin()) {
  54. $objDBackUser = new DBackUser();
  55. $user = $objDBackUser->get(self::getUid());
  56. $platfrom = $user['platfrom'];
  57. $tmpPlatformList = array();
  58. foreach ($platfrom as $tmpPlatformId) {
  59. $tmpPlatformList[] = $platformList[$tmpPlatformId];
  60. }
  61. $platformList = $tmpPlatformList;
  62. }
  63. // 获取是否授权配置参数配置
  64. $authorize = LotteryEvents::getAuthorize ();
  65. // 获取是是否在列表中显示配置
  66. $listDisplay = LotteryEvents::getListDisplay ();
  67. // 是否推荐到焦点图
  68. $focusDisplay = LotteryEvents::getFocusDisplay ();
  69. // 是否置顶
  70. $topDisplay = LotteryEvents::getTopDisplay ();
  71. $objDCategory = new Category ();
  72. $categoryList = $objDCategory->getsAll ();
  73. // 音乐图标位置
  74. $getMusicPosition = LotteryEvents::getMusicPosition ();
  75. // 导航
  76. $navConfig = $this->getCreatePageNav($thisType,$thisBigType);
  77. // 微信相关模块 不包含类型
  78. $weixinFormNotType = array(
  79. LotteryEvents::TYPE_EVENTS_OTHER,
  80. );
  81. $this->setOutput ( 'weixinFormNotType', $weixinFormNotType );
  82. // 音乐相关 不包含类型
  83. $musicFormNotType = array(
  84. LotteryEvents::TYPE_EVENTS_CUT_SCREEN,
  85. );
  86. $this->setOutput ( 'musicFormNotType', $musicFormNotType );
  87. // 切屏方向 不包含的类型
  88. $cutDirectionFormNotType = array(
  89. LotteryEvents::TYPE_EVENTS_CUT_SCREEN,
  90. );
  91. $this->setOutput ( 'cutDirectionFormNotType', $cutDirectionFormNotType );
  92. $this->tpl = 'admin/activity/page_create';
  93. $title = '基础设置';
  94. $this->setOutput('title', $title);
  95. $this->setOutput('menu_active', array('name' => 'quickpublish', 'item' => '')); //激活菜单
  96. $this->addNavMenu('活动列表');
  97. $this->addNavMenu($title);
  98. $this->setOutput ( 'navConfig', $navConfig );// 导航 显示 URL 配置
  99. $this->setOutput ( 'getMusicPosition', $getMusicPosition );
  100. $this->setOutput ( 'platformList', $platformList );
  101. $this->setOutput ( 'categoryList', $categoryList );// 获取所有发布列表(平台列表)
  102. $this->setOutput ( 'focusDisplay', $focusDisplay );
  103. $this->setOutput ( 'topDisplay', $topDisplay );
  104. $this->setOutput ( 'authorize', $authorize );
  105. $this->setOutput ( 'listDisplay', $listDisplay );
  106. $this->setOutput ( 'getMusicPosition', $getMusicPosition );
  107. $this->setOutput ( 'thisBigType', $thisBigType ); // 当前选择大类
  108. $this->setOutput ( 'thisType', $thisType ); // 当前选择类型
  109. $this->setOutput ( 'typeData', $typeData ); // 所有活动类型
  110. $this->setOutput ( 'bigTypeConfig', $bigTypeConfig ); // 所有活动类型
  111. $this->setOutput('typeDesc', $typeData[$thisType]['desc']);
  112. $this->setOutput('pagePublicData', $this->getPagePublicData()); // 后台管理相关数据
  113. }
  114. /**
  115. * 事件: 创建活动 基础设置
  116. * 请求地址:http://cas.lishuy.com/?c=Admin_Activity_SetBasics&a=ReqCreate
  117. * 参数:见方法内 $info
  118. */
  119. public function doReqCreate() {
  120. $info ['type'] = Request::p ( 'type' ); // 获取所选类型
  121. $info ['img_url'] = Request::p('img_url'); // 活动头图 img_url 表单名称 img_url
  122. $info ['events_name'] = Request::p ( 'events_name' ); // 活动标题 events_name 时间戳
  123. if ($info['type'] == LotteryEvents::TYPE_EVENTS_ARTICLE) {
  124. $info ['begin_time'] = date('Y-m-d H:i');
  125. } else {
  126. $info ['begin_time'] = Request::p ( 'begin_time' ) ? Request::p ( 'begin_time' ) : '2025-01.01 00:00:00'; // 活动开始时间 begin_time 时间戳
  127. }
  128. $info ['begin_time'] = strtotime($info ['begin_time']);
  129. $info ['end_time'] = Request::p ( 'end_time' ) ? Request::p ( 'end_time' ) : '2025-01.01 00:00:00'; // 活动结束时间 end_time
  130. $info ['end_time'] = strtotime($info ['end_time']);
  131. $tmp_platform_ids = $_POST['platform_ids']; // 所属"列表"IDs platform_ids_str
  132. foreach ( $tmp_platform_ids as $platform_id ) {
  133. $info ['platform_ids'] += $platform_id;
  134. }
  135. $info ['weixinShare'] ['imgUrl'] = Request::p('wx_img_url'); // 分享图片 weixinShare[imgUrl] 表单名称 wx_img_url
  136. $info ['weixinShare'] ['title'] = Request::p ( 'weixinShare_title' ); // 分享标题 weixinShare[title]
  137. $info ['weixinShare'] ['content'] = Request::p ( 'weixinShare_content' ); // 分享内容 weixinShare[content]
  138. $info ['weixinShare'] ['jump_url'] = Request::p ( 'weixinShare_jump_url' ); // 分享后跳转地址 weixinShare[jump_url]
  139. $info ['authorize'] = Request::p ( 'authorize' ); // 是否需要登录 authorize
  140. $info ['list_display'] = Request::p ( 'list_display' ); // 是否在列表中出现
  141. $info ['top_display'] = Request::p ( 'top_display' );
  142. $info ['focus_display'] = Request::p ( 'focus_display' );
  143. $info ['category_id'] = Request::p ( 'category_id' );
  144. $info ['participation_user_num'] = Request::p ( 'participation_user_num' ); // 每天用户参与次数 participation_user_num
  145. $info ['participation_ip_num'] = Request::p ( 'participation_ip_num' ); // 允许每天IP参与次数 participation_ip_num
  146. $info ['participation_user_all_num'] = Request::p ( 'participation_user_all_num' ); // 允许用户参与次数 participation_user_all_num
  147. $info ['winning_user_num'] = Request::p ( 'winning_user_num' ); // 允许用户获奖次数 winning_user_num
  148. $info['cut_fx'] = Request::p('cut_fx'); // 切屏方向
  149. $info ['music_url'] = Request::p('music_url'); // 获取背景音乐 music_url 表单名称:music_url
  150. $info ['operator_uid'] = $this->operatorData['uid'];// 创建人UID
  151. $info ['other_url'] = Request::p ( 'other_url' ); // 跳转地址
  152. $info ['music_position'] = Request::p ( 'music_position' ); // 音乐图标位置 music_position
  153. $info['loading_bg_color'] = Request::p('loading_bg_color');
  154. $info['loading_text_color'] = Request::p('loading_text_color');
  155. $info ['setPageType'] = 'Basics';
  156. // 执行添加方法
  157. $events_id = $this->objLottery->addLotteryEvents ( $info );
  158. if (! $events_id) {
  159. $this->ajax_fail_exit('基础设置失败');
  160. }
  161. $objPlatform = new Platform();
  162. $formData = $objPlatform -> getsAll();
  163. $eventData = $this->objLottery->getOneLotteryEvents($events_id);
  164. foreach ( $tmp_platform_ids as $platform_id ) {
  165. $url = $this->objLottery ->getEventsUrl($info ['type'], $eventData['create_time'],$formData[$platform_id]['url']);
  166. $this->createImgCodeUrl($url);
  167. }
  168. // 更具不同活动 大类型 跳转 到不同的地址
  169. $bigTypeConfig = LotteryEvents::getBigTypeConfig ();
  170. if(in_array($info['type'], $bigTypeConfig['Event'])){
  171. $redirect_url = Request::schemeDomain () . "/?c=Admin_Activity_SetInteractive&a=PageShow&events_id={$events_id}";
  172. }else{
  173. $redirect_url = Request::schemeDomain () . "/?c=Admin_Activity_SetPage&a=PageShow&events_id={$events_id}";
  174. }
  175. if($info['type'] == LotteryEvents::TYPE_EVENTS_OTHER){
  176. $redirect_url = Request::schemeDomain () . "/?c=Admin_Activity_DeliveryChannels&a=PageList&events_id={$events_id}";
  177. }
  178. $this->ajax_success_exit($redirect_url);
  179. }
  180. /**
  181. * 页面: 修改&查看 活动基础设置 doPageShow
  182. * 地址:http://cas.lishuy.com/?c=Admin_Activity_SetBasics&a=PageShow&events_id=nnn
  183. * 参数:events_id 活动ID
  184. */
  185. public function doPageShow() {
  186. $events_id = Request::g('events_id');
  187. $eventData =$this->objLottery->getOneLotteryEvents($events_id);
  188. $typeData = LotteryEvents::getType ();
  189. $bigTypeConfig = LotteryEvents::getBigTypeConfig ();
  190. $platformList = array ();
  191. $objDPlatform = new Platform ();
  192. $platformList = $objDPlatform->getsAll ();
  193. if (!self::isSuperadmin()) {
  194. $objDBackUser = new DBackUser();
  195. $user = $objDBackUser->get(self::getUid());
  196. $platfrom = $user['platfrom'];
  197. $tmpPlatformList = array();
  198. foreach ($platfrom as $tmpPlatformId) {
  199. $tmpPlatformList[] = $platformList[$tmpPlatformId];
  200. }
  201. $platformList = $tmpPlatformList;
  202. }
  203. $authorize = LotteryEvents::getAuthorize ();
  204. // 获取是是否在列表中显示配置
  205. $listDisplay = LotteryEvents::getListDisplay ();
  206. // 是否推荐到焦点图
  207. $focusDisplay = LotteryEvents::getFocusDisplay ();
  208. // 是否置顶
  209. $topDisplay = LotteryEvents::getTopDisplay ();
  210. $objDCategory = new Category ();
  211. $categoryList = $objDCategory->getsAll ();
  212. $getMusicPosition = LotteryEvents::getMusicPosition ();
  213. $navConfig = $this->getUpPageNav($events_id, 'Basics');
  214. // 微信相关模块 不包含类型
  215. $weixinFormNotType = array(
  216. LotteryEvents::TYPE_EVENTS_OTHER,
  217. );
  218. $this->setOutput ( 'weixinFormNotType', $weixinFormNotType );
  219. // 音乐相关 不包含类型
  220. $musicFormNotType = array(
  221. LotteryEvents::TYPE_EVENTS_CUT_SCREEN,
  222. );
  223. $this->setOutput ( 'musicFormNotType', $musicFormNotType );
  224. // 切屏方向 不包含的类型
  225. $cutDirectionFormNotType = array(
  226. LotteryEvents::TYPE_EVENTS_CUT_SCREEN,
  227. );
  228. $this->setOutput ( 'cutDirectionFormNotType', $cutDirectionFormNotType );
  229. // 发货状态 不包含的类型
  230. $deliveryFormNotType = array(
  231. LotteryEvents::TYPE_EVENTS_CUT_SCREEN,
  232. LotteryEvents::TYPE_EVENTS_ARTICLE,
  233. LotteryEvents::TYPE_EVENTS_OTHER,
  234. LotteryEvents::TYPE_EVENTS_CODE,
  235. LotteryEvents::TYPE_EVENTS_INVITATION,
  236. LotteryEvents::TYPE_EVENTS_VOTE,
  237. );
  238. $this->setOutput ( 'deliveryFormNotType', $deliveryFormNotType );
  239. $deliveryDesc = LotteryEvents::getDeliveryType (); // 发货状态
  240. if(!$eventData['delivery']){
  241. $eventData['delivery'] = LotteryEvents::DELIVERY_FALSE;
  242. }
  243. $this->setOutput ( 'deliveryDesc', $deliveryDesc );
  244. $this->tpl = 'admin/activity/page_show';
  245. $title = '基础设置';
  246. $this->setOutput('title', $title);
  247. $this->setOutput('menu_active', array('name' => 'mypublish', 'item' => '')); //激活菜单
  248. $this->addNavMenu('活动列表');
  249. $this->addNavMenu($title);
  250. $objDPlatform = new Platform();
  251. $platFormData = $objDPlatform -> getsAll();
  252. # 获取当前活动都添加哪些 列表
  253. # 返回列表IDs
  254. $platFormIds = array();
  255. foreach($platFormData as $key => $data){
  256. if($eventData['platform_ids']&$key){
  257. $platFormIds[$key] = $key;
  258. }
  259. }
  260. $this->setOutput('displayDesc', LotteryEvents::getDisplay());
  261. $this->setOutput ( 'navConfig', $navConfig ); // 导航显示 URL 配置
  262. $this->setOutput ( 'getMusicPosition', $getMusicPosition );// 音乐图标位置
  263. $this->setOutput ( 'platformList', $platformList );// 获取所有发布列表(平台列表)
  264. $this->setOutput ( 'categoryList', $categoryList );// 获取所有发布列表(平台列表)
  265. $this->setOutput ( 'listDisplay', $listDisplay ); // 获取是否在列表中显示
  266. $this->setOutput ( 'focusDisplay', $focusDisplay );
  267. $this->setOutput ( 'topDisplay', $topDisplay );
  268. $this->setOutput ( 'authorize', $authorize );// 获取是否登录配置参数配置
  269. $this->setOutput ( 'typeData', $typeData ); // 所有活动类型
  270. $this->setOutput ( 'thisType', $eventData['type'] ); // 所有活动类型
  271. $this->setOutput ( 'bigTypeConfig', $bigTypeConfig ); // 所有活动类型
  272. $this->setOutput ( 'eventData', $eventData ); // 当前活动详情
  273. $this->setOutput('platFormIds', $platFormIds);
  274. $this->setOutput('pagePublicData', $this->getPagePublicData($events_id)); // 后台管理相关数据
  275. }
  276. /**
  277. * 事件: 修改活动基础设置 doReqUp
  278. * 地址:http://cas.lishuy.com/?c=Admin_Activity_SetBasics&a=PageShow&events_id=nnn
  279. * 参数:见方法内
  280. */
  281. public function doReqUp() {
  282. $events_id = Request::p('events_id');
  283. $info ['img_url'] = Request::p('img_url'); // 活动头图 img_url 表单名称 img_url
  284. // $tmpImgData = $this->loadImg ( 'img_url' );
  285. // if (is_array ( $tmpImgData )) {
  286. // $info ['img_url'] = $tmpImgData ['url'] [0];
  287. // }
  288. $info ['events_name'] = Request::p ( 'events_name' ); // 活动标题 events_name 时间戳
  289. $info ['begin_time'] = Request::p ( 'begin_time' ) ? Request::p ( 'begin_time' ) : '2025-01.01 00:00:00'; // 活动开始时间 begin_time 时间戳
  290. $info ['begin_time'] = strtotime($info ['begin_time']);
  291. $info ['end_time'] = Request::p ( 'end_time' ) ? Request::p ( 'end_time' ) : '2025-01.01 00:00:00'; // 活动结束时间 end_time
  292. $info ['end_time'] = strtotime($info ['end_time']);
  293. /*
  294. $tmp_platform_ids = $_POST['platform_ids'];
  295. foreach ( $tmp_platform_ids as $platform_id ) {
  296. $info ['platform_ids'] += $platform_id;
  297. }
  298. */
  299. $info ['weixinShare'] ['imgUrl'] = Request::p('wx_img_url'); // 分享图片 weixinShare[imgUrl] 表单名称 wx_img_url
  300. // $tmpImgData = $this->loadImg ( 'wx_img_url' );
  301. // if (is_array ( $tmpImgData )) {
  302. // $info ['weixinShare'] ['imgUrl'] = $tmpImgData ['url'] [0];
  303. // }
  304. $info ['weixinShare'] ['title'] = Request::p ( 'weixinShare_title' ); // 分享标题 weixinShare[title]
  305. $info ['weixinShare'] ['content'] = Request::p ( 'weixinShare_content' ); // 分享内容 weixinShare[content]
  306. $info ['weixinShare'] ['jump_url'] = Request::p ( 'weixinShare_jump_url' ); // 分享后跳转地址 weixinShare[jump_url]
  307. $info ['authorize'] = Request::p ( 'authorize' ); // 是否需要登录 authorize
  308. $info ['list_display'] = Request::p ( 'list_display' ); // 是否在列表中出现
  309. $info ['top_display'] = Request::p ( 'top_display' );
  310. $info ['focus_display'] = Request::p ( 'focus_display' );
  311. $info ['category_id'] = Request::p ( 'category_id' );
  312. $info ['delivery'] = Request::p ( 'delivery' ); // 是否发货
  313. $info ['participation_user_num'] = Request::p ( 'participation_user_num' ); // 每天用户参与次数 participation_user_num
  314. $info ['participation_ip_num'] = Request::p ( 'participation_ip_num' ); // 允许每天IP参与次数 participation_ip_num
  315. $info ['participation_user_all_num'] = Request::p ( 'participation_user_all_num' ); // 允许用户参与次数 participation_user_all_num
  316. $info ['winning_user_num'] = Request::p ( 'winning_user_num' ); // 允许用户获奖次数 winning_user_num
  317. $info['cut_fx'] = Request::p('cut_fx'); // 切屏方向
  318. $info ['music_url'] = Request::p('music_url'); // 获取背景音乐 music_url 表单名称:music_url
  319. $info['loading_bg_color'] = Request::p('loading_bg_color');
  320. $info['loading_text_color'] = Request::p('loading_text_color');
  321. // $tmpMusicData = $this->loadMusic ( 'music' );
  322. // if (is_array ( $tmpMusicData )) {
  323. // $info ['music_url'] = $tmpMusicData ['url'] [0];
  324. // }
  325. $info ['music_position'] = Request::p ( 'music_position' ); // 音乐图标位置 music_position
  326. $display = Request::p ( 'display' );
  327. if($display!=null){
  328. $info ['display'] = $display;
  329. }
  330. # 修改操作
  331. $tmpData = $this->objLottery->upLotteryEvents($info, array('id' => $events_id));
  332. if(!$tmpData){
  333. $this->ajax_fail_exit('修改失败');
  334. }
  335. $this->setNowUpPage($events_id, 'Basics');
  336. $this->ajax_success_exit(Request::schemeDomain () . "/?c=Admin_Activity_SetBasics&a=PageShow&events_id={$events_id}");
  337. }
  338. /**
  339. * 上传音乐
  340. *
  341. * @param string $files_name
  342. */
  343. public function loadMusic($files_name = 'music') {
  344. $uploadConfig = Config::getInstance ()->get ( 'upload' );
  345. // 定义允许上传的文件扩展名
  346. $ext_arr = array (
  347. 'music' => array (
  348. 'mp3'
  349. )
  350. );
  351. if (! is_array ( $_FILES [$image_name] ['name'] )) {
  352. foreach ( $_FILES [$image_name] as $key => $data ) {
  353. unset ( $_FILES [$image_name] [$key] );
  354. $_FILES [$image_name] [$key] [] = $data;
  355. }
  356. }
  357. $file_url = array ();
  358. foreach ( $_FILES [$image_name] ['name'] as $key => $oneData ) {
  359. // 文件保存目录路径
  360. $save_path = $uploadConfig ['path'] . '/';
  361. $save_path = realpath ( $save_path ) . '/';
  362. // PHP上传失败
  363. if ($_FILES [$image_name] ['error'] [$key] != 0) {
  364. switch ($_FILES [$image_name] ['error'] [$key]) {
  365. case '1' :
  366. $error = '超过php.ini允许的大小。';
  367. break;
  368. case '2' :
  369. $error = '超过表单允许的大小。';
  370. break;
  371. case '3' :
  372. $error = '音乐只有部分被上传。';
  373. break;
  374. case '4' :
  375. $error = '请选择音乐文件。';
  376. break;
  377. case '6' :
  378. $error = '找不到临时目录。';
  379. break;
  380. case '7' :
  381. $error = '写文件到硬盘出错。';
  382. break;
  383. case '8' :
  384. $error = 'File upload stopped by extension。';
  385. break;
  386. case '999' :
  387. default :
  388. $error = '未知错误。';
  389. }
  390. return $error;
  391. }
  392. // 有上传文件时
  393. if (empty ( $_FILES ) === false) {
  394. // 原文件名
  395. $file_name = $_FILES [$image_name] ['name'] [$key];
  396. // 服务器上临时文件名
  397. $tmp_name = $_FILES [$image_name] ['tmp_name'] [$key];
  398. // 文件大小
  399. $file_size = $_FILES [$image_name] ['size'] [$key];
  400. // 检查文件名
  401. if (! $file_name) {
  402. return "请选择文件。";
  403. }
  404. // 检查目录
  405. if (@is_dir ( $save_path ) === false) {
  406. return "上传目录不存在。";
  407. }
  408. // 检查目录写权限
  409. if (@is_writable ( $save_path ) === false) {
  410. return "上传目录没有写权限。";
  411. }
  412. // 检查是否已上传
  413. if (@is_uploaded_file ( $tmp_name ) === false) {
  414. return "上传失败。";
  415. }
  416. // 检查目录名
  417. $dir_name = 'music';
  418. if (empty ( $ext_arr [$dir_name] )) {
  419. return "目录名不正确。";
  420. }
  421. // 获得文件扩展名
  422. $temp_arr = explode ( ".", $file_name );
  423. $file_ext = array_pop ( $temp_arr );
  424. $file_ext = trim ( $file_ext );
  425. $file_ext = strtolower ( $file_ext );
  426. // 检查扩展名
  427. if (in_array ( $file_ext, $ext_arr [$dir_name] ) === false) {
  428. return "上传文件扩展名是不允许的扩展名。\n只允许" . implode ( ",", $ext_arr [$dir_name] ) . "格式。";
  429. }
  430. // 创建文件夹
  431. $ymd = date ( "Ymd" );
  432. $ymd = date ( "Y" ) . '/' . date ( 'md' );
  433. // 文件保存目录URL
  434. $save_url = $uploadConfig ['url'] . '/';
  435. $new_file_name = '';
  436. $save_path .= $dir_name . "/" . $ymd . "/";
  437. $save_url .= $dir_name . "/" . $ymd . "/";
  438. if (! file_exists ( $save_path )) {
  439. if (! mkdir ( $save_path, 0775, true )) {
  440. return "创建目录失败:{$save_path}";
  441. }
  442. }
  443. // 新文件名
  444. $new_file_name = date ( "His" ) . '_' . rand ( 10000, 99999 ) . '.' . $file_ext;
  445. // 移动文件
  446. $file_path = $save_path . $new_file_name;
  447. // 原图上传
  448. if (move_uploaded_file ( $tmp_name, $file_path ) === false) {
  449. return "上传文件失败。";
  450. }
  451. @chmod ( $file_path, 0777 );
  452. $file_url [$key] = $file_path;
  453. }
  454. }
  455. return array (
  456. 'error' => 0,
  457. 'url' => $file_url
  458. );
  459. }
  460. /**
  461. * 方法:图片上传
  462. */
  463. public function loadImg($image_name = 'image') {
  464. $uploadConfig = Config::getInstance ()->get ( 'upload' );
  465. // 定义允许上传的文件扩展名
  466. $ext_arr = array (
  467. 'image' => array (
  468. 'gif',
  469. 'jpg',
  470. 'jpeg',
  471. 'png',
  472. 'bmp'
  473. )
  474. );
  475. if (! is_array ( $_FILES [$image_name] ['name'] )) {
  476. foreach ( $_FILES [$image_name] as $key => $data ) {
  477. unset ( $_FILES [$image_name] [$key] );
  478. $_FILES [$image_name] [$key] [] = $data;
  479. }
  480. }
  481. $file_url = array ();
  482. foreach ( $_FILES [$image_name] ['name'] as $key => $oneData ) {
  483. // 文件保存目录路径
  484. $save_path = $uploadConfig ['path'] . '/';
  485. $save_path = realpath ( $save_path ) . '/';
  486. // PHP上传失败
  487. if ($_FILES [$image_name] ['error'] [$key] != 0) {
  488. switch ($_FILES [$image_name] ['error'] [$key]) {
  489. case '1' :
  490. $error = '超过php.ini允许的大小。';
  491. break;
  492. case '2' :
  493. $error = '超过表单允许的大小。';
  494. break;
  495. case '3' :
  496. $error = '图片只有部分被上传。';
  497. break;
  498. case '4' :
  499. $error = '请选择图片。';
  500. break;
  501. case '6' :
  502. $error = '找不到临时目录。';
  503. break;
  504. case '7' :
  505. $error = '写文件到硬盘出错。';
  506. break;
  507. case '8' :
  508. $error = 'File upload stopped by extension。';
  509. break;
  510. case '999' :
  511. default :
  512. $error = '未知错误。';
  513. }
  514. return $error;
  515. }
  516. // 有上传文件时
  517. if (empty ( $_FILES ) === false) {
  518. // 原文件名
  519. $file_name = $_FILES [$image_name] ['name'] [$key];
  520. // 服务器上临时文件名
  521. $tmp_name = $_FILES [$image_name] ['tmp_name'] [$key];
  522. // 文件大小
  523. $file_size = $_FILES [$image_name] ['size'] [$key];
  524. // 检查文件名
  525. if (! $file_name) {
  526. return "请选择文件。";
  527. }
  528. // 检查目录
  529. if (@is_dir ( $save_path ) === false) {
  530. return "上传目录不存在。";
  531. }
  532. // 检查目录写权限
  533. if (@is_writable ( $save_path ) === false) {
  534. return "上传目录没有写权限。";
  535. }
  536. // 检查是否已上传
  537. if (@is_uploaded_file ( $tmp_name ) === false) {
  538. return "上传失败。";
  539. }
  540. // 检查目录名
  541. $dir_name = 'image';
  542. if (empty ( $ext_arr [$dir_name] )) {
  543. return "目录名不正确。";
  544. }
  545. // 获得文件扩展名
  546. $temp_arr = explode ( ".", $file_name );
  547. $file_ext = array_pop ( $temp_arr );
  548. $file_ext = trim ( $file_ext );
  549. $file_ext = strtolower ( $file_ext );
  550. // 检查扩展名
  551. if (in_array ( $file_ext, $ext_arr [$dir_name] ) === false) {
  552. return "上传文件扩展名是不允许的扩展名。\n只允许" . implode ( ",", $ext_arr [$dir_name] ) . "格式。";
  553. }
  554. // 创建文件夹
  555. $ymd = date ( "Ymd" );
  556. $ymd = date ( "Y" ) . '/' . date ( 'md' );
  557. // 文件保存目录URL
  558. $save_url = $uploadConfig ['url'] . '/';
  559. $new_file_name = '';
  560. $save_path .= $dir_name . "/" . $ymd . "/";
  561. $save_url .= $dir_name . "/" . $ymd . "/";
  562. if (! file_exists ( $save_path )) {
  563. if (! mkdir ( $save_path, 0775, true )) {
  564. return "创建目录失败:{$save_path}";
  565. }
  566. }
  567. // 新文件名
  568. $new_file_name = date ( "His" ) . '_' . rand ( 10000, 99999 ) . '.' . $file_ext;
  569. // 移动文件
  570. $file_path = $save_path . $new_file_name;
  571. // 原图上传
  572. if (move_uploaded_file ( $tmp_name, $file_path ) === false) {
  573. return "上传文件失败。";
  574. }
  575. error_reporting ( E_ALL );
  576. // 压缩65质量原图
  577. $this_basename = basename ( $file_path );
  578. $this_dirname = dirname ( $file_path );
  579. $z_file_path = $this_dirname . '/' . 'z.' . $this_basename;
  580. Image::transformFormat ( $file_path, $z_file_path, 'JPG' );
  581. @chmod ( $file_path, 0777 );
  582. $file_url [$key] = $save_url . 'z.' . $new_file_name;
  583. }
  584. }
  585. return array (
  586. 'error' => 0,
  587. 'url' => $file_url
  588. );
  589. }
  590. public function display() {
  591. return $this->render ();
  592. }
  593. }