首页 > php代码 > php discuz chhome 图片上传swfupload功能

php discuz chhome 图片上传swfupload功能

php discuz chhome 图片上传swfupload功能

这上传与discuz来比, 还相差太远. 功能也欠缺.

除了部分内置的url引向,我们改不了之外, 其它的数据都是可以修改的.

<?php
/*
 [UCenter Home] (C) 2007-2008 Comsenz Inc.
 $Id: do_swfupload.php 12830 2009-07-22 06:42:32Z zhengqingpeng $
*/
if (!defined('IN_UCHOME')) { //入门牌.
    exit('Access Denied');
}
include_once (S_ROOT . './source/function_cp.php');
$op = empty($_GET['op']) ? '' : $_GET['op']; // uchome比较喜欢用的方法变量.
$isupload = empty($_GET['cam']) && empty($_GET['doodle']) ? true : false; //是否上传.还有种可能是头像上传.
$iscamera = isset($_GET['cam']) ? true : false; //判断一下是头像上传.
$isdoodle = isset($_GET['doodle']) ? true : false; //判断一下是大头贴背景是否随机.
$fileurl = ''; // 默认赋值.
if (!empty($_POST['uid'])) { //如果有uid传过来, 表示在上传头像, 就取得uid值.
    $_SGLOBAL['supe_uid'] = intval($_POST['uid']); //强制转化.
    if (empty($_SGLOBAL['supe_uid']) || $_POST['hash'] != md5($_SGLOBAL['supe_uid'] . UC_KEY)) { // 既然传递了uid值是过来, 假如用户没有登录,及hash码不对应,就中断.
        exit();
    }
} elseif (empty($_SGLOBAL['supe_uid'])) { //否则再判断, 如果没有登录, 禁止使用上传功能.
    showmessage('to_login', 'do.php?ac=' . $_SCONFIG['login_action']);
}
if ($op == "finish") { //上传结束时.
    /* 它会传入如下GET
    array (
           'ac' => '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'] < 1) { //&ucirc;��Ϳѻ��
            $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 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\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


教程网址:http://www.phprm.com/code/4a4c046559fd2b4d419b26825bafc4d9.html

欢迎收藏∩_∩但请保留本文链接。

标签:none

发表留言