===================Discuz! x2====================
首先我们进入 相册批量上传 从地址栏可以分析 home.php?mod=spacecp&ac=upload&op=flash&albumid=0
访问的文件是 source\module\home\home_spacecp.php
此文件底部 require_once libfile('spacecp/'.$ac, 'include');
调用source\include\spacecp\spacecp_upload.php
进入这部分
- if(!checkperm('allowupload')) {
- showmessage('no_privilege_upload', '', array(), array('return' => true));
- }
- cknewuser();
- $config = urlencode($_G['siteroot'].'home.php?mod=misc&ac=swfupload&op=config'.($_GET['op'] == 'cam'? '&cam=1' : ''));
- $albums = getalbums($_G['uid']);
- $actives = ($_GET['op'] == 'flash' || $_GET['op'] == 'cam')?array($_GET['op']=>' class="a"'):array('js'=>' class="a"');
- $maxspacesize = checkperm('maxspacesize');
- if(!empty($maxspacesize)) {
- space_merge($space, 'count');
- space_merge($space, 'field_home');
- $maxspacesize = $maxspacesize + $space['addsize'] * 1024 * 1024;
- $haveattachsize = ($maxspacesize < $space['attachsize'] ? '-':'').formatsize($maxspacesize - $space['attachsize']);
- } else {
- $haveattachsize = 0;
- }
- require_once libfile('function/friend');
- $groups = friend_group_list();
- loadcache('albumcategory');
- $category = $_G['cache']['albumcategory'];
- $categoryselect = '';
- if($category) {
- include_once libfile('function/portalcp');
- $categoryselect = category_showselect('album', 'catid', !$_G['setting']['albumcategoryrequired'] ? true : false, $_GET['catid']);
- }
- }
复制代码 此处的代码中 $config = urlencode($_G['siteroot'].'home.php?mod=misc&ac=swfupload&op=config'.($_GET['op'] == 'cam'? '&cam=1' : ''));
是访问flash 处理文件的入口
include_once template("home/spacecp_upload");
然后调用模版文件,下面我们来查看模版相应的相册批量上传部分的代码- <script type="text/javascript">
- document.write(AC_FL_RunContent(
- 'width', '100%', 'height', '400',
- 'src', '{IMGDIR}/album_upload.swf?config=$config&albumid=$_GET[albumid]',
- 'quality', 'high', 'wmode', 'transparent'
- ));
- </script>
复制代码 代码中的config来自 上面提到的$config 这部分代码,这部分代码用来显示flash,来自于static/js/common.js
接下来,访问将进入flash处理的关键部分
source\include\misc\misc_swfupload.php
首次执行的是
- } elseif($op == 'config') {
- $hash = md5($_G['uid'].UC_KEY);
- $uploadurl = urlencode(getsiteurl().'home.php?mod=misc&ac=swfupload'.($iscamera ? '&op=screen' : ($isdoodle ? '&op=doodle&from=':'')));
- .......中间代码省略
- $albums = getalbums($_G['uid']);
- //系统分类
- loadcache('albumcategory');
- $categorys = $_G['cache']['albumcategory'];
- $categorystat = $_G['setting']['albumcategorystat'] ? intval($_G['setting']['albumcategorystat']) : 0;
- $categoryrequired = $_G['setting']['albumcategoryrequired'] ? intval($_G['setting']['albumcategoryrequired']) : 0;
复制代码 代码中$albums = getalbums($_G['uid']);
//系统分类
loadcache('albumcategory');
$categorys = $_G['cache']['albumcategory'];
用于获取用户的相册分类,这也是容易出错的地方(当用户在后台开启了相册分类,但是没有设置分类项,导致$categorys为空)
$categorystat = $_G['setting']['albumcategorystat'] ? intval($_G['setting']['albumcategorystat']) : 0;
用于调用返回给flash的相册分类xml文件(template\default\home\misc_swfupload.htm)
当第一次访问完 misc_swfupload.php文件 将返回xml文件给flash 用于显示,主要处理在文件底部
如果返回的xml文件有错误将导致flash上显示不正确,或者终止继续运行,导致flash停滞。返回正常程序将通过用户提交上传图片将再次访问 该文件 进入- elseif($_FILES && $_POST) {
- if($_FILES["Filedata"]['error']) {
- $uploadfiles = lang('spacecp', 'file_is_too_big');
- } else {
- $_FILES["Filedata"]['name'] = addslashes(diconv(urldecode($_FILES["Filedata"]['name']), 'UTF-8'));
- $_POST['albumid'] = addslashes(diconv(urldecode($_POST['albumid']), 'UTF-8'));
- $catid = $_POST['catid'] ? intval($_POST['catid']) : 0;
- $uploadfiles = pic_save($_FILES["Filedata"], $_POST['albumid'], addslashes(diconv(urldecode($_POST['title']), 'UTF-8')), true, $catid);
- }
- $proid = $_POST['proid'];
- $uploadResponse = true;
- $albumid = 0;
- if($uploadfiles && is_array($uploadfiles)) {
- $status = "success";
- $albumid = $uploadfiles['albumid'];
- } else {
- $status = "failure";
- }
- }
复制代码 其中$uploadfiles = pic_save($_FILES["Filedata"], $_POST['albumid'], addslashes(diconv(urldecode($_POST['title']), 'UTF-8')), true, $catid); 作用是保存图片(从临时目录移动到服务器端,达到上传文件效果),(函数来自source\function\function_spacecp.php)
到此,相册批量上传图片已基本结束。
|