<?php

if (!empty($_GET['del']))
{
    $file = $_GET['del'];
    if (preg_match("/^\d+_\d+\.\w+$/", $_GET['del']))
    {
        @unlink(ABSPATH . 'uploads/others/' . $_GET['del']);
    } else
    {
        yun_error('操作未定义');
    }
    yun_succeed('删除成功', url(RPGMA . '?win&' . randstr()), false);
}
if (IS_POST)
{
    if (empty($_FILES['upfile']['name']))
    {
        setval('method', 'ajax');
        yun_error('请选择要上传的文件');
    }
    $ext = strtolower(str_replace('.', '', strrchr($_FILES['upfile']['name'], '.')));
    $ext == 'php' && yun_error('不允许上传php文件');
    $wname = TIME . '_' . mt_rand(1000, 9999);
    if (@move_uploaded_file($_FILES['upfile']['tmp_name'], ABSPATH .
        'uploads/others/' . $wname . '.' . $ext))
    {
        yun_succeed('上传成功', url(RPGMA . '?win&' . randstr()), false);
    }
    yun_error('上传失败');
}
$arr = array();
$farr = glob(ABSPATH . 'uploads/others/*.*');
$farr === false && $farr = array();
foreach ($farr as $file)
{
    $filename = strtolower(str_replace('/', '', strrchr($file, '/')));
    $ext = strtolower(str_replace('.', '', strrchr($file, '.')));
    $arr[$filename] = array(in_array($ext, array('jpg', 'jpeg', 'gif', 'bmp', 'png')),
        ROOTPATH . 'uploads/others/' . $filename, $filename);
}
krsort($arr);
arg($arr);

?>