php discuz chhome 图片上传swfupload功能
这上传与discuz来比, 还相差太远. 功能也欠缺.
除了部分内置的url引向,我们改不了之外, 其它的数据都是可以修改的.
'swfupload',
'op' => 'finish',
'albumid' => '2',
)*/
$albumid = intval($_get['albumid']); //取得分类id.
$space = getspace($_sglobal['supe_uid']); //更新用户部分记录, 比较图片总数, 容量计算.
if(ckprivacy('upload', 1)) { //判断一下是否已经写了推送.
include_once(s_root.'./source/function_feed.php');
feed_publish($albumid, 'albumid'); //否则就再写一次.
}
//强行中断.
exit();
} elseif($op == 'config') { //swf上传的配置.
/* 根据抓取所得 get传过来:
array (
'ac' => 'swfupload',
'op' => 'config',
)
*/
$hash = md5($_sglobal['supe_uid'].uc_key); //生成一个hash码.
if($isupload && !checkperm('allowupload')) { //是上传图片,并且权限足够.对于配置来说, $isupload永远为假.
$hash = '';
} else {
$filearr = $dirstr = array(); //初始化数组. 文件数组/及目录数据.
if($iscamera) { //进入头像上传工作.
/*
根据抓取, get数据如下:
array (
'ac' => 'swfupload',
'op' => 'config',
'cam' => '1',
)
*/
$directory = sreaddir(s_root.'./image/foreground'); //大头贴背景的目录. sreaddir读取里面的目录数据.
foreach($directory as $key => $value) { //每一个背景都是独立的一个目录, 所以循环一下.
$dirstr = s_root.'./image/foreground/'.$value; //合成新的路径.
if(is_dir($dirstr)) { //判断一下是否是目录.
$filearr = sreaddir($dirstr, array('jpg','jpeg','gif','png')); //读取目录里面的图片文件.
if(!empty($filearr)) { // 如果图片数组不为空.
if(is_file($dirstr.'/categories.txt')) { // 如果categories.txt文件存在.
$catfile = @file($dirstr.'/categories.txt'); //打开此文件.
$dirarr[$key][0] = trim($catfile[0]); //就将里面的文件读取来. 当然, 很无谓的方法, 里面的内容与目录名是一样的.
} else { //如果txt文件不存在, 就取得目录名.
$dirarr[$key][0] = trim($value); //准确取得值, trim多用.
}
$dirarr[$key][1] = trim('image/foreground/'.$value.'/'); //将指针1设置为当前大头贴背景目录.
$dirarr[$key][2] = $filearr; // //将指针2设置为当前大头贴背景目录里面的图片.
}
}
}
} elseif($isdoodle) { //如果是头像随机背景, 就读取./image/doodle/big里面的图片文件.
$filearr = sreaddir(s_root.'./image/doodle/big', array('jpg','jpeg','gif','png'));
}
}
//接着就到了图片上传配置工作.
$max = @ini_get(upload_max_filesize); //取得php.ini最大上传值.
$unit = strtolower(substr($max, -1, 1)); //$max结尾有kb字样吧, 要截取一下,并且转成小写.
//下面是针对不同的计算单元作换算.
if($unit == 'k') {
$max = intval($max)*1024; //看样子是全部转成byt字节单位. kb x 1024 = 多少字节.
} elseif($unit == 'm') {
$max = intval($max)*1024*1024; // mb x 1024 x 1024 = 多少字节.
} elseif($unit == 'g') {
$max = intval($max)*1024*1024*1024; // gb x 1024 x 1024 x 1024 = 多少字节.
}
//取得用户所建立的分类数组.
$albums = getalbums($_sglobal['supe_uid']);
} elseif($op == screen || $op == doodle) { // screen 不理解什么时候出来 || 随机大头贴背景,由于没有摄像头, 这里面略过.
if(empty($globals['http_raw_post_data'])) {
$globals['http_raw_post_data'] = file_get_contents(php://input);
}
$status = failure;
$dosave = true;
if($op == doodle) {
$query = $_sglobal['db']->query('select * from '.tname('usermagic'). where uid = '$_sglobal[supe_uid]' and mid = 'doodle');
$value = $_sglobal['db']->fetch_array($query);
if(empty($value) || $value['count'] $uploadfiles = -8;
$dosave = false;
}
}
if($dosave && !empty($globals['http_raw_post_data'])) {
$_server['http_albumid'] = addslashes(siconv(urldecode($_server['http_albumid']), $_sc['charset'], utf-8));
$from = false;
if($op == 'screen') {
$from = 'camera';
} elseif($_get['from'] == 'album') {
$from = 'uploadimage';
}
$_sconfig['allowwatermark'] = 0;
$uploadfiles = stream_save($globals['http_raw_post_data'], $_server['http_albumid'], 'jpg', '', '', 0, $from);
}
$uploadresponse = true;
$picid = $proid = $albumid = 0;
if($uploadfiles && is_array($uploadfiles)) {
$status = success;
$albumid = $uploadfiles['albumid'];
$picid = $uploadfiles['picid'];
if($op == doodle) {
$fileurl = pic_get($uploadfiles['filepath'], $uploadfiles['thumb'], $uploadfiles['remote'], 0);
include_once(s_root.'./source/function_magic.php');
magic_use('doodle', array(), 1);
}
} else {
switch ($uploadfiles) {
case -1:
$uploadfiles = cplang('inadequate_capacity_space');
break;
case -2:
$uploadfiles = cplang('only_allows_upload_file_types');
break;
case -4:
$uploadfiles = cplang('ftp_upload_file_size');
break;
case -8:
$uploadfiles = cplang('has_not_more_doodle');
break;
default:
$uploadfiles = cplang('mobile_picture_temporary_failure');
break;
}
}
} elseif($_files && $_post) { // 图片上传时,
/* 根据抓取, post get数据值为:
post = array (
'filename' => 'mjp45+r3001.jpg',
'proid' => '1',
'albumid' => '2',
'uid' => '1',
'title' => 'mjp45+r3001',
'hash' => '11ed07fe235ca5b9e509043e85419785',
'upload' => 'submit query',
)
get = array (
'ac' => 'swfupload',
)
*/
if($_files[filedata]['error']) { //如果有上传错误
$uploadfiles = cplang('file_is_too_big'); // 就提示文件过大.
} else {
//考虑到编码及大小写问题, 还有转义. 取得上传文件名.
$_files[filedata]['name'] = addslashes(siconv(urldecode($_files[filedata]['name']), $_sc['charset'], utf-8));
//考虑到编码及大小写问题, 还有转义. 取得上传分类id.
$_post['albumid'] = addslashes(siconv(urldecode($_post['albumid']), $_sc['charset'], utf-8));
//考虑到编码及大小写问题, 还有转义. 取得上传文件后的一个详解路径.
$uploadfiles = pic_save($_files[filedata], $_post['albumid'], addslashes(siconv(urldecode($_post['title']), $_sc['charset'], utf-8)));
}
//根据我的分析, 以下内容在图片上传时没用, 不知头像上传会否用到.
$proid = $_post['proid'];
$uploadresponse = true;
$albumid = 0;
//判断一下上传文件, 及上传文件数组.
if($uploadfiles && is_array($uploadfiles)) {
$status = success; //上传完成
$albumid = $uploadfiles['albumid']; // 上传的分类id
} else {
$status = failure; //这就是上传失败了.
}
//这是我自己加上去的, 估计uchome也会感激我.
exit();
}
// 时间
$newalbumname = sgmdate('ymd');
//引入模板
include template(do_swfupload);
//输出xml, swf配置需要.
$outxml = n;
$outxml .= siconv(ob_get_contents(), 'utf-8');
obclean();
@header(expires: -1);
@header(cache-control: no-store, private, post-check=0, pre-check=0, max-age=0, false);
@header(pragma: no-cache);
@header(content-type: application/xml; charset=utf-8);
echo $outxml;
// 配置文件具体导出什么内容呢? 请访问这个网址.
//http://u.discuz.net/home/do.php?ac=swfupload&op=config
?>