<?php
if (empty($_FILES['upfile']['name']))
{
    setval('method', 'ajax');
    yun_error(mlang('请选择要上传的文件'));
}
$temp_f = glob(ABSPATH . 'uploads/temp/*.*');
$temp_f === false && $temp_f = array();
count($temp_f) > 203 && yun_error(mlang('系统临时文件已满,请稍候重试'));
/**
 *清理过期附件 
 */

$sun = 0;
$time = 3600;
foreach ($temp_f as $file)
{
    $filename = strtolower(str_replace('/', '', strrchr($file, '/')));
    $ex = explode('_', $filename);
    if ((TIME - $time) > $ex[1])
    {
        unlink($file);
        continue;
    }
    if ($user['id'] == $ex[0])
        $sun++;
}
empty($bpv[2]) && $sun > 5 && yun_error(mlang('附件超限.您需要等待一段时间'));
if (IS_POST)
{
    $ext = strtolower(str_replace('.', '', strrchr($_FILES['upfile']['name'], '.')));
    in_array($ext, $conf['upext']) or yun_error(mlang('不允许上传该类型文件'));
    $wname = $user['id'] . '_' . TIME . '_' . mt_rand(1000, 9999);
    if (@move_uploaded_file($_FILES['upfile']['tmp_name'], ABSPATH . 'uploads/temp/' .
        $wname . '.' . $ext))
    {
        $tm_arr = array();
        /**
         * 生成缩略图
         */
        if (!empty($_POST['isthumb']) && in_array($ext, array('png', 'gif', 'jpg',
            'jpeg')))
        {
            $tm_arr = system::thumb(ABSPATH . 'uploads/temp/' . $wname . '.' . $ext, $wname);
        }
        is_array($tm_arr) or $tm_arr = array();
        $tm_arr[] = $wname . '.' . $ext;
        $html = '';
        while (list(, $val) = @each($tm_arr))
        {
            $v = explode('_', $val);
            $html .= '<li><input name=\"\" value=\"' . ROOTPATH . 'uploads/temp/' . $val . '\" style=\"width:400px\" readonly=\"readonly\"/> ' .
                date('H:i:s', $v[1]) . '</li>';
        }
        yun_succeed(mlang('上传成功'), 'parent.document.getElementById(\'form2\').style.display.value=\'\';var yun_annexs=parent.document.getElementById(\'yun_annex\').innerHTML;parent.document.getElementById(\'yun_annex\').innerHTML="' .
            $html . '"+yun_annexs;');
    } else
    {
        yun_error(mlang('上传失败'));
    }
}
?>