function uploaduserfile($userid, $file)
{
    global $mysqli;
    global $filesystemroot;
    $cmd = 'uploaduserfile';
    $success = TRUE;
    $data = NULL;
    try {
        if (isauthenticated()) {
            $useridtype = $userid;
            $userid = $userid == "auto_generate" ? getlastcreateduserid() + 1 : $userid;
            $directory = $filesystemroot . "audiogallery/user_{$userid}/";
            mkdir($directory);
            if ($file["error"] > 0) {
                throw new Exception(geterrormsg(106), 106);
            } else {
                if (file_exists($directory . $file["name"])) {
                    throw new Exception(geterrormsg(108), 108);
                } else {
                    if (move_uploaded_file($file["tmp_name"], $directory . $file["name"])) {
                        $data = array("fileuploaded" => TRUE);
                        //resizing the image to thumb size
                        $sourcefile = $directory . $file["name"];
                        generateandsavethumb($sourcefile, $sourcefile);
                        if ($useridtype != "auto_generate") {
                            $query = "SELECT avatar FROM user WHERE id={$userid};";
                            if ($result = $mysqli->query($query)) {
                                if ($tuple = $result->fetch_array()) {
                                    $userthumb = $filesystemroot . "audiogallery/user_{$userid}/" . $tuple['avatar'];
                                    deletefile($userthumb);
                                }
                            }
                        }
                    } else {
                        throw new Exception(geterrormsg(106), 106);
                    }
                }
            }
        } else {
            throw new Exception(geterrormsg(101), 101);
        }
        output($cmd, $success, $data);
    } catch (Exception $e) {
        $success = FALSE;
        $data = array("errorcode" => $e->getCode(), "errormsg" => $e->getMessage());
        output($cmd, $success, $data);
    }
}
Example #2
0
            } else {
                $DreamCMS->db->update('page', $data, compact('id'));
                redirect($name . "编辑完成!", "admincp.php?do=catalog");
            }
        }
        if ($action == 'reupload') {
            $fid = (int) $_POST['fid'];
            $rs = $DreamCMS->db->get_row("SELECT * FROM `#DC@__file` WHERE `id`='{$fid}' LIMIT 1");
            $path = str_replace(array($DreamCMS->config['uploadfiledir'] . '/', $rs->filename), '', $rs->path);
            uploadfile('file', '', $path, $rs->filename, 'reupload');
            alert($rs->filename . '重新上传成功!', 'javascript:window.parent.location.reload();');
        }
        if (isset($_POST['delete'])) {
            $i = 0;
            foreach ($_POST['delete'] as $fid) {
                deletefile($fid) && $i++;
            }
            alert("共删除{$i}个文件!", "url:1");
        } else {
            _header();
        }
        break;
}
function deletefile($fid)
{
    global $DreamCMS;
    $rs = $DreamCMS->db->get_row("SELECT * FROM `#DC@__file` WHERE `id`='{$fid}' LIMIT 1");
    delfile(DCPATH . $rs->path);
    if ($rs->thumbpath) {
        delfile(DCPATH . $rs->thumbpath);
        $DreamCMS->db->query("UPDATE `#DC@__article` SET `pic`='' WHERE `pic`='{$rs->thumbpath}'");
    createapp();
}
if ($function == addnote) {
    addnote();
}
if ($function == testingfile) {
    testingfile();
}
if ($function == testingfile1) {
    testingfile1();
}
if ($function == addfile) {
    addfile();
}
if ($function == deletefile) {
    deletefile();
}
if ($function == cancelapp) {
    cancelapp();
}
if ($function == filestable) {
    filestable();
}
if ($function == get_file) {
    get_file();
}
function createapp()
{
    $fname = $_POST['Purpose'];
    $lname = $_POST['Note'];
    $sid = $_POST['studentid'];