频道直达 - 专题 - 新闻 - 技巧 - 组网 - 开发 - 安全 - web编程 - 图像 - 操作系统 - 数据库 - 教育 - 旅游 - 健康 - 时尚 - 驱动 - 软件 - 游戏 - 多媒体 - ERP - 讨论组

无组件上传图片至SQLSERVER数据库(示例)

来源: 作者: 出处:巧巧读书 2006-09-09 进入讨论组

  在无组件上传我刚试成功,所以提供代码给大家一起共享。

/* addemployee.ASP */
<HTML>
<head>
<title>职工之家</title>
<meta http-equiv="Content-Type" content="text/HTML; charset=gb2312">
<link rel="stylesheet" href=../../"../CSS/site_CSS.CSS" type="text/CSS">
</head>

<script language="javascript">
<!--
//选择分类
///////////////////////////////////////////////////////////////////////
function selectsort(txtSubject){
var returnValue
returnValue=window.showModalDialog("selMode.htm",null,"center:1;status:0;help:0;resized:0;dialogheight:300px;dialogwidth:206px");
if (returnValue!="" && returnValue!=null){
txtSubject.value=returnValue
}
}
///////////////////////////////////////////////////////////////////////
//合法性检查
function isOK(thisForm){
var strTemp,strValue,strLen,strExName
 if(thisForm.txtTitle.value==""){
alert("提示:标题不能为空,请正确输入")
thisForm.txtTitle.focus()
return false
}
if(thisForm.txtSort.value==""){
alert("提示:请正确选择分类")
thisForm.txtSort.focus()
return false
}
/*检查图片类型*/
if(thisForm.file.value!=""){
strTemp=thisForm.file.value
strValue=strTemp.toLowerCase()
strLen=strTemp.length
strExName=strValue.substring(strLen-4,strLen)
if (strExName!=".jpg" && strExName!=".gif"){
alert("请选择jpg或者gif文件!")
return false
}
return true
}
}
//-->
</script>

<body bgcolor="#FFFFFF" text="#000000" leftmargin="1" topmargin="1">
<form name="form1" method="post" action="transact1.ASP" enctype="multipart/form-data">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td colspan="2" bgcolor="#006699" height="15">&nbsp;</td>
</tr>
<tr>
<td class="textBlack">
<div align="right">标题:</div>
</td>
<td>
<input type="text" name="txtTitle" size="52" class="textarea">
</td>
</tr>
<tr>
<td class="textBlack">
<div align="right">分类:</div>
</td>
<td>
<input type="text" name="txtSort" size="35" class="textarea">
<input type="button" name="Submit2" class="buttonSkid" onclick="selectsort(txtSort);">
</td>
</tr>
<tr>
<td class="textBlack" valign="top">
<div align="right">正文:</div>
</td>
<td>
<textarea name="txtContent" rows="15" cols="50" class="textarea"></textarea>
</td>
</tr>
<tr>
<td height="14" class="textBlack" valign="top">
<div align="right">图片:</div>
</td>
<td height="14" class="textBlack">
<div align="left">
<input type="file" name="file" size="35" class="textarea">
</div>
</td>
</tr>
<tr>
<td height="42" class="textBlack" valign="top">&nbsp;</td>
<td height="42" class="textBlack" valign="middle">
<p>1、您上传的图片大小请控制在<font color="#FF0000"><b>500K</b></font>以内,否则不允许上传<br>
2、你上传的图片必须为<font color="#FF0000"><b>150*130象素</b></font><br>
3、上传上传图片的格式为JPG或者GIF</p>
</td>
</tr>
<tr>
<td height="39" class="textBlack">&nbsp;</td>
<td height="39" valign="middle">
<div align="center"><img src=../../"../images/save.gif" width="85" height="19" onClick="if(isOK(form1)){form1.submit()}">  
<img src=../../"../images/close.gif" width="85" height="19" onClick="self.close();" ></div>
</td>
</tr>
</table>
</form>
</body>
</HTML>
*************************************************************************

/* transact1.ASP*/
<!--#include file="../func/conn.inc"-->
<!--#include file="../func/fupload.inc"-->
<!--#include file ="../func/myfunctions.inc"-->
<%
If Request.ServerVariables("REQUEST_METHOD") = "POST" Then
Dim Fields
Dim strTitle,strSort,strContent
Dim rs,sSql
Dim iMaxid
Dim strMaxid
Dim strlen

Set Fields = GetUpload()
strTitle=BinaryToString(Fields("txtTitle").value)
strSort=BinaryToString(Fields("txtSort").value)
strContent=BinaryToString(Fields("txtContent").value)
strSort=split(trim(strSort),"-")

if instr(1,lcase(Fields("file").FileName),".jpg")=0 and instr(1,lcase(Fields("file").FileName),".gif")=0 then
response.write "<script language='javascript'>alert('上传的图片必须是gif或者jpg格式的图片')</script>"
response.write "<script language='javascript'>window.location='addemployee.ASP';</script>"
Response.end
end if

if Fields("file").Length>500000 then
response.write "<script language='javascript'>alert('只允许不大于500k的图片上传');</script>"
response.write "<script language='javascript'>window.location='addemployee.ASP';</script>"
response.end
end if

'/*存至数据库*/
if Fields("file").FileName<>"" then
Set rs=Server.CreateObject("ADODB.Recordset")
sSql="select * from employee order by id desc"
rs.open sSql,conn,2,2
if not rs.eof then
iMaxid=Clng(rs("id"))+1
strlen=4-len(cstr(iMaxid))
strMaxid=string(strlen,"0") & cstr(i静态页面:http://www.qqread.com/sqlserver/2006/10/y238563.html 更多文章 更多内容请看数据库专栏数据库处理专题城域网专题专题,或进入讨论组讨论。
收藏此文】【 】【打印】【关闭
相关图文阅读
频道图文推荐
健 康 咨 询
时 尚 咨 询
巧巧读书宗旨
相关专题
最新论坛文章
站内各频道最新更新文档
站内最新制作专题
热门关键字导读
Photoshop教 程照片处理 照片制作 PS快捷键 抠图
计 算 机 故 障XP系统修复
艺 术 与 设 计设计 流媒体 设计欣赏 边框
计 算 机 安 全ARP
站内频道文章精选
巧巧电脑频道编辑信箱  告诉我们您想看的专题或文章