|
发表于 2005-4-6 14:07:05
|
显示全部楼层
[code:1]
$upload_file = isset($_FILES['attach_article']['name']) ? $_FILES['attach_article']['name'] : '';
$upload_tmp_file = isset($_FILES['attach_article']['tmp_name']) ? $_FILES['attach_article']['tmp_name'] : '';
$upload_dir = getcwd() . "/uploads/attach_article/";
$filename = $upload_dir . $upload_file;
$pinfo = pathinfo($filename);
$extension = $pinfo[extension];
$sql = "SELECT unsafe_extension
FROM " . TABLE_PREFIX . "unsafe_ext
WHERE unsafe_extension = '$extension' ";
$db->SetFetchMode(ADODB_FETCH_ASSOC);
$result = $db->Execute($sql);
if (!$result) {
echo $db->ErrorMsg();
} else {
$row = $result->fetchRow(ADODB_FETCH_ASSOC);
}
if ( !$row ) {
if ( !empty($upload_file) ) {
if ( !file_exists($filename) ) {
if ( move_uploaded_file($upload_tmp_file, $filename) ) {
$upload_time = time();
$user_id = $_SESSION['user_id'];
$sql = "SELECT username
FROM " . TABLE_PREFIX . "users
WHERE user_id = '$user_id' ";
$username = $db->getOne($sql);
$upload_user = $username;
$sql = "INSERT INTO " . TABLE_PREFIX . "attach_article(attach_name, attach_desc,
upload_time, username, sub_cat_id)
VALUES ('$upload_file', '$attach_desc', '$upload_time', '$upload_user', '$sub_cat_id') " ;
if ($db->Execute($sql) === false) {
echo 'error inserting: '.$db->ErrorMsg().'<BR>';
} else {
$sql = "SELECT attach_name
FROM " . TABLE_PREFIX . "attach_article
WHERE username = '$upload_user'
AND article_id = '0' ";
$upload_succeed_attach = $db->getCol($sql);
$template->assign(array(
"L_NOTE_POST" => sprintf($lang['upload_succeed'], count($upload_succeed_attach))
)
);
}
} else {
$template->assign(array(
"L_NOTE_POST" => sprintf($lang['upload_failed'], $upload_file)
)
);
}
} else {
$template->assign(array(
"L_NOTE_POST" => sprintf($lang['upload_exist'], $upload_file)
)
);
}
} else {
$template->assign(array(
"L_NOTE_POST" => $lang['null_attach_article']
)
);
}
} else {
$template->assign(array(
"L_NOTE_POST" => sprintf($lang['forbidden_upload_type'], $extension)
)
);
}
[/code:1] |
|