请教上传图片的路径写入数据库问题(附代码)

hrtop 2007-12-09 11:08:52
代码如下:
<%dim ifphoto
if grade<=1 then
set rs=Server.CreateObject("ADODB.recordset")
rs.open"select count(id) from love_photo where userid="&userid&"",conn,1,1
ifphoto=rs(0)
rs.close:set rs=nothing
if ifphoto>3 then
closeconn
Call msg("Sorry!\n\n普通会员最多只能上传3张照片\n\n请到照片管理中心删除部分照片","-1")
end if
elseif grade=2 or grade=3 then
set rs=Server.CreateObject("ADODB.recordset")
rs.open"select count(id) from love_photo where userid="&userid&"",conn,1,1
ifphoto=rs(0)
rs.close:set rs=nothing
if ifphoto>30 then
closeconn
Call msg("Sorry!\n\n诚信会员、会长最多只能上传30张照片\n\n请到照片管理中心删除部分照片","-1")
end if
end if
%>
<!--#include file="sub/uploadinc2.0.asa"-->
<!--#include file="sub/photo_picsize.asa"-->
<%
If Trim(request("Action"))="Upload" then
Call UploadData()
End If
Sub UploadData()
Dim upload
Server.ScriptTimeOut=999999
set upload=new UpFile_Class ''建立上传对象
Dim ProductId,ClassId,ProductName,ProductSize,SmallPic,SmallPicSize,BigPic,BigPicSize,title,S_Height,S_Width
S_Width=100
S_Height=100
Title=Replace(Replace(Replace(upload.form("Title"),"'",""),"<","<"),">",">")
if Trim(Title)="" then
closeconn:set upload=nothing
Call msg("照片说明不能空白!请重试。","-1")
end if
'图片处理
dim file,fileExt,Filesize
'BigPic=UserID'用户ID
BigPic=FormatDT(now(), 9)&cdstr(9)
set file=upload.file("Pic")
FileType=Ucase(file.FileType)
fileExt=file.fileExt
Filesize=file.FileSize
If Filesize>0 then
If instr(FileType,"JPEG")<=0 and instr(FileType,"GIF")<=0 Then
set file=nothing:set upload=nothing:Closeconn
Call msg("错误图片文件格式,必须是 jpg、gif。","-1")
End If
If Filesize>202400 Then
set file=nothing:set upload=nothing:Closeconn
Call msg("图片大小已经超出上传范围(200K)。","-1")
Else
ManageFilePath="/uploadphoto/"&formatdt(now(),10)
ChkFod(ManageFilePath) '校对上传目录
SmallPic=ManageFilePath&"/s_"&UserID&"_"&BigPic&"."&fileExt '小图片路径
SmallPic_db=formatdt(now(),10)&"/s_"&UserID&"_"&BigPic&"."&fileExt
BigPic_db=formatdt(now(),10)&"/b_"&UserID&"_"&BigPic&"."&fileExt
BigPic=ManageFilePath&"/b_"&UserID&"_"&BigPic&"."&fileExt '大图片路径

file.SaveAs Server.mappath(BigPic) '无组件保存原始图片
set qswh=new picsize '调用图片规格类
arr=qswh.getimagesize(server.mappath(BigPic)) '打开保存原始图片后的路径
BigPicSize=arr(1)&"×"&arr(2) '返回原始图片规格
set arr=nothing
set qswh=nothing
Dim pic_height,pic_width,BBB
pic_height=split(BigPicSize,"×")(1)
pic_height_sy=pic_height
pic_width=split(BigPicSize,"×")(0)
pic_width_sy=pic_width
if pic_height>S_Height then
BBB=Int(100*S_Height/(pic_height+0.0001)+0.5)/100
pic_width=pic_width*BBB
pic_height=pic_height*BBB
End If
'和以上同理
if pic_width>S_Width Then '如果图片宽度大于范围宽度
BBB=Int(100*S_Width/(pic_width+0.0001)+0.5)/100 '计算出缩略的百分比
pic_width=pic_width*BBB '计算出缩略后的宽度尺寸
pic_height=pic_height*BBB '计算出缩略后的高度尺寸
end if
Set Photo = Server.CreateObject("Persits.Jpeg") '调用图片处理组件
Photo.Open Server.MapPath(BigPic)
Photo.Width = pic_width
Photo.Height = pic_height
Photo.Save Server.MapPath(SmallPic)
Set Photo = nothing
set qswh=new picsize
arr=qswh.getimagesize(server.mappath(SmallPic))
SmallPicSize=arr(1)&"×"&arr(2)
set arr=nothing
set qswh=nothing
Set Photo = Server.CreateObject("Persits.Jpeg")
Photo.Open Server.MapPath(BigPic)
If pic_width_sy>600 or pic_height_sy>600 Then
Set Logo = Server.CreateObject("Persits.Jpeg")
LogoPath = Server.MapPath("/images/06/photoLogo.gif")
Logo.Open LogoPath
Logo.Width = 172 '更改水印图片的宽度
Logo.Height = Logo.Width * Logo.OriginalHeight / Logo.OriginalWidth '按照原先的长宽比计算新的水印高度
Photo.DrawImage photo.width-192, photo.height-64, Logo,1,&H000000,100 '在这里可以更改水印所在的位置(photo.width-87,photo.height-19 这里我是放在了图片的右下角)还可以更改水印的透明度(我定义为0.7) ,&HFFFFFF,100
Set Logo = nothing
Elseif (pic_width_sy>200 and pic_width_sy<600) or (pic_height_sy>200 and pic_height_sy<600) Then'打开水印图片
Set Logo = Server.CreateObject("Persits.Jpeg")
LogoPath = Server.MapPath("/images/06/photoLogo_x.gif")
Logo.Open LogoPath
Logo.Width = 100 '更改水印图片的宽度
Logo.Height = Logo.Width * Logo.OriginalHeight / Logo.OriginalWidth '按照原先的长宽比计算新的水印高度
Photo.DrawImage photo.width-110, photo.height-36, Logo,1,&H000000,100 '在这里可以更改水印所在的位置(photo.width-87,photo.height-19 这里我是放在了图片的右下角)还可以更改水印的透明度(我定义为0.7) ,&HFFFFFF,100
Set Logo = nothing
Else'打开文字水印
photo.Canvas.Font.Color = &HFFFFFF
photo.Canvas.Font.Family = "Arial"
photo.Canvas.Font.Bold = True
photo.Canvas.Font.size = 15
photo.Canvas.Print 10, photo.OriginalHeight-17, "yanjiao.cc" '10为左边距,100为上边距
End if
Photo.Save Server.MapPath(BigPic)
Set Photo = nothing
End If
Else
set file=nothing
set upload=nothing:closeconn '释放上传对象
Call MsgOut("请选择本地的照片。","",1)
end if
set file=nothing
set upload=nothing '释放上传对象
'信息入库
set rs= Server.CreateObject("ADODB.Recordset")
rs.open"select username,picurl_s,picurl_b,title,userid from love_photo",conn,1,3
Rs.addnew
rs("username")=username
rs("userid")=userid
rs("picurl_s")=SmallPic_db
rs("picurl_b")=BigPic_db
rs("title")=title
rs.update
rs.close:set rs=nothing:closeconn
response.redirect "u_photo_list.asp"
End Sub
%>

现在图片可以上传了,但是上传图片的路径却没有写进数据库,请教各位大侠,问题出在什么地方呢?
...全文
256 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
Go 旅城通票 2007-12-10
  • 打赏
  • 举报
回复
但是上传图片的路径却没有写进数据库

其他信息写进去没有??

如果其他信息写入了而图片没有,那应该是你的其他函数把变量值改变过了
pzhuyy 2007-12-10
  • 打赏
  • 举报
回复
楼主不懂调试,鉴定完毕:)

一步一步的来,上传正常,就从上传后的代码开始,
把变量Response.write 出来,

一边Response.write
一边Response.end
跟踪变量:)
如果跟踪到入库的时候都没有问题,就可以把sql语句显示出来,在测试.

PS:个人偏向于用insert 语句插入库,这样
cow8063 2007-12-10
  • 打赏
  • 举报
回复
response.write SmallPic_db
....
分别打出来看看有没有值先
  • 打赏
  • 举报
回复
首先你先打印SmallPic_db BigPic_db 这两个值,看能打印出来吗?
能打印出来,再把
Rs.addnew
rs("username")=username
rs("userid")=userid
rs("picurl_s")=SmallPic_db
rs("picurl_b")=BigPic_db
rs("title")=title
rs.update
换成sql="insert into love_photo(username,picurl_s,picurl_b,title,userid) values('"&username &"','"&SmallPic_db&"','"&BigPic_db&"','"&title&"',"&userid&")"
打印出来,放到查询分析器中执行
如果能插入,说明你的程序有问题
不能插入,那你的sql就有问题,或者你得到的字段类型不对
搬运工865 2007-12-09
  • 打赏
  • 举报
回复
你输出下 看看有值么?

rs("username")=username
rs("userid")=userid
rs("picurl_s")=SmallPic_db
rs("picurl_b")=BigPic_db
rs("title")=title

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧