asp 会员头像上传 代码
有排版的页面http://hi.baidu.com/xnaer/item/5a430e5f53e8d61bdb1635ea
思路:
会员通过文件域上传图片;
将图片名改为 会员ID+.jpg;
在要显示头像图片的地方插入该图片链接。
代码:
——————————1.asp————————————
<form name="form1" method="post" action="2.asp"> 上传本地图片: <input name="file" type="file" class="input" id="file" size="30"> <p>可上传的图片格式为 .GIF, .PNG, .BMP, .JPG, .JPEG 。</p> <p>文件大小请限制在30KB以内。</p> <input name="Submit" type="submit" class="button" value="提交"> </form>
——————————2.asp————————————
<%@LANGUAGE="VBSCRIPT"%>   '脚本语言为VB <!--#include file="Connections/*.asp" -->   '链接数据库 <% Dim index__MMColParam index__MMColParam = "0" If (Session("MM_Username") <> "") Then index__MMColParam = Session("MM_Username") End If %>   '记录集筛选为 ID = 阶段变量 MM_Username <% Dim index Dim index_cmd Dim index_numRows
Set index_cmd = Server.CreateObject  ("ADODB.Command") index_cmd.ActiveConnection =  MM_nculive_STRING index_cmd.CommandText = "SELECT ID FROM *.associator WHERE  ID = ?"  index_cmd.Prepared = true index_cmd.Parameters.Append  index_cmd.CreateParameter("param1", 200, 1, 12, index__MMColParam) '  adVarChar
Set index = index_cmd.Execute index_numRows = 0 %>    '绑定记录集,查询会员ID <% Dim  fn %> <%fn=(index.Fields.Item("ID").Value)%>    '获取会员ID <% Dim file,filename,houzui,fso file =  Request.Form("file")   '获取文件地址
If file=""  then response.write"<script>alert('请选择要上传的文件!');window.location.href='infoupdata.asp';</script>"    '如果没有获取不到文件 else houzui=LCase(mid(file,InStrRev(file, ".")))    '后缀名小写化
If houzui=".gif" or houzui=".jpg" or houzui=".jpeg" or  houzui=".bmp" or houzui=".png" then   '限制后缀名
set  fso=server.createobject("scripting.filesystemobject") set  f=fso.getfile(file)   '获取文件大小 If f.size<=30720 Then   '比较文件大小 filename  = fn & ".jpg"   '修改文件名
Set objStream =  Server.CreateObject("ADODB.Stream") objStream.Type =  1 objStream.Open objStream.LoadFromFile file objStream.SaveToFile  Server.MapPath("headpic/" & filename),2 objStream.Close    '上传文件,高亮引号内为目标文件夹
response.write"<script>alert('图片上传成功!');window.location.href='infoupdata.asp';</script>" else response.write"<script>alert('不允许上传大于30KB的图片!');window.location.href='infoupdata.asp';</script>" end  If else response.write"<script>alert('不允许上传" & houzui &  "格式的图片!');window.location.href='infoupdata.asp';</script>" end  If end If %> <% index.Close() Set index = Nothing %>    '关闭记录集
——————————————————————————
至此,头像图片的上传已经结束,接下来该显示图片了。
首先绑定记录集,以 ID = 阶段变量 MM_Username 筛选会员ID。
然后在必要的地方插入下面的代码
——————————3.asp————————————
<img src="headpic/<%=(index.Fields.Item("ID").Value)%>.jpg" width="120" height="120" onerror="this.src='默认头像地址'" />
——————————————————————————
现在,完美结束。
 
                    
                     
                    
                 
                    
                 
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号