关于图片编辑的问题

yoyoyuye 2009-11-03 02:37:12
使用的是长葛视窗上传程序v1.0。在对图片进行编辑的时候。如果选择了图片的地址,那么可以替换掉已有图片,进行编辑。但是如果没有图片上传,也就是说,图片不进行编辑,只替换其他的内容。就报错
编辑的代码是


。。。。。。。。。。。。。。。。。。。。
<form action="editmancp.asp?did=<%=Operid%>" method="post" name="cfrm" enctype="multipart/form-data">
<table width="450px" cellpadding="0" cellspacing="0" border="1" bgcolor="#f0f8ff" style="line-height:20px;margin:0 auto" align="center">
<tr><td colspan="2" bgcolor="#4da6ff" align="center">编辑产品</td></tr>
<tr><td bgcolor="#e4e4e4">产品名称:</td>
<td bgcolor="#ffffff" align="left">
<input type="hidden" name="sOrgTitle" value="<%=rs("name")%>" />
<input type="text" maxlength="50" name="name" size="15" value="<%=rs("name")%>"/>
</td>
</tr>
<tr><td bgcolor="#e4e4e4" width="100px">产品图片:</td>
<td bgcolor="#ffffff" align="left"><input type="file" name="file_up1" size="25" value="admin_agr/<%=rs("url")%>">
上传图片,<%if rs("url")<>"" then response.Write("<a href='/admin_agr/"&rs("url")&"' target=_blank><font color=red>图</font>")%>
</td>
</tr>
<tr>
<td bgcolor="#e4e4e4" align="right">内容:</td><td bgcolor="#ffffff"></td></tr>
<tr><td bgcolor="#ffffff" colspan="2">
<textarea name="content2" style="display:none"><%if rs("photointro")<>"" then response.Write(server.HTMLEncode(rs("photointro")))%></textarea>
<IFRAME ID="eWebEditor1" Src="eWebEditor.asp?id=content2&style=standard" FRAMEBORDER="0" SCROLLING="no" WIDTH="450" HEIGHT="240"></IFRAME>
</td></tr>
<tr><td bgcolor="#e4e4e4">是否推荐:</td>
<td bgcolor="#ffffff" align="left">
<select name="classid" id="classid">
<option value="0" <%if rs("classid")=0 then response.Write("selected")%>>不推荐</option>
<option value="1" <%if rs("classid")=1 then response.Write("selected")%>>推荐</option>
</select>
</td>
</tr>
<tr>
<td bgcolor="#e4e4e4"> </td>
<td bgcolor="#FFFFFF" align="center">
<input name="id" type="hidden" value="<%=rs("id")%>">
<input type="hidden" name="CopyrightInfo" value="by paladin">
<input type="hidden" name="filepath" value="paladin">
<input type="hidden" name="act" value="upload">
<input type="submit" value=" 编辑 " name="submit">
</td>
</tr>
</table>
</form>
。。。。。。。。。。。。。。。。。。。。



editmancp.asp的代码是


<!--#include file="../conn/conn.asp" -->
<!--#include file="upload.inc"-->
<%'on error resume next%>
<%
dim upload,file,formName,formPath,iCount,filename,fileExt,i
set upload=new upload_5xSoft '建立上传对象
id=upload.Form("id")
photointro=HTMLEncode2(upload.form("content2"))
name=upload.form("name")
formPath=upload.form("filepath")
classid=upload.form("classid")
'在目录后加(/)
if right(formPath,1)<>"/" then formPath=formPath&"/"
iCount=0

for each formName in upload.file '列出所有上传了的文件
set file=upload.file(formName) '生成一个文件对象

if file.filesize<0 then
response.redirect "error.asp?errid=4"
response.end
end if
if file.filesize>2000000 then
response.redirect "error.asp?errid=6"
response.end
end if

fileExt=lcase(right(file.filename,4))
if fileEXT<>".gif" and fileEXT<>".jpg" and fileEXT<>".png" then
response.redirect "error.asp?errid=7"
response.end
end if

filenamett=file.FileName
filenamet=year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&file.FileName
filename=formPath&filenamet

filesize=file.filesize
if file.FileSize>0 then '如果 FileSize > 0 说明有文件数据
file.SaveAs Server.mappath(filename) '保存文件
iCount=iCount+1
end if

set file=nothing

FilePath=Server.MapPath(".")
FilePath=FilePath & "\paladin\"
Set Jpeg = Server.CreateObject("Persits.Jpeg")
Jpeg.Open (FilePath & filenamet)

'开始变更所有文件扩展名为jpg
filenamelen=len(filenamet)
filenamelen=filenamelen-4
filenamet1=filenamet
filenamet=left(filenamet,filenamelen)
filenamet=filenamet&".jpg"
'结束文件名变更

'开始判断哪边为长边,以长边进行缩放
imgWidth=Jpeg.OriginalWidth
imgHeight=Jpeg.OriginalHeight

if imgWidth>=imgHeight and imgWidth>120 then
Jpeg.Width=150
Jpeg.Height=Jpeg.OriginalHeight/(Jpeg.OriginalWidth/150)
end if
if imgHeight>imgWidth and imgHeight>113 then
Jpeg.Height=113
Jpeg.Width=Jpeg.OriginalWidth/(Jpeg.OriginalHeight/113)
end if

Jpeg.Sharpen 1, 130
Jpeg.Save (FilePath & "small_" & filenamet)
'写入数据库
yy=year(date)
mm=right("00"&month(date),2)
dd=right("00"&day(date),2)
idate=yy & "-" & mm & "-" & dd & " "

xx=right("00"&hour(time),2)
ff=right("00"&minute(time),2)
mm=right("00"&second(time),2)
itime=xx & ":" & ff & ":" & mm

itime=idate&itime

photourlb=formPath & filenamet1
'if imgwidth<320 and imgheight<240 then
photourls=formPath & "small_" & filenamet
set rs=server.CreateObject("ADODB.RecordSet")
sql="select * from propic where id="&clng(id)
rs.open sql,conn,1,3
rs("name")=name
rs("photointro")=photointro
if imgheight<>"" then rs("imgh")=imgheight '判断是否有图片上传,有就传之,否则不传
if imgwidth<>"" then rs("imgw")=imgwidth
if filesize<>"" then rs("filesize")=filesize
if photourlb<>"" then rs("url")=photourlb
if photourls<>"" then rs("surl")=photourls
rs("classid")=classid
rs.update
next

set upload=nothing '删除对象
response.write "<SCRIPT language=JavaScript>alert('文件上传成功,返回!');"
response.write "history.go(-1);</SCRIPT>"


function HTMLEncode2(fString)
fString = Replace(fString, CHR(13), "")
fString = Replace(fString, CHR(10) & CHR(10), "</P><P>")
fString = Replace(fString, CHR(10), "<BR>")
HTMLEncode2 = fString
end function
%>




谢谢大家
...全文
93 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
yoyoyuye 2009-11-03
  • 打赏
  • 举报
回复
谢谢大家,尤其是5楼的兄弟。占用你很多时间来帮我解决问题,非常感谢
fjfndfjf 2009-11-03
  • 打赏
  • 举报
回复
看来主要问题是出在 上传的图片为空引起的。。。

如果不想更新图片,但又想保存内容修改,那可以对上传图片出错时用个变量保存错误代码

再根据错误代码进行确定是否更新产品图片。。。


editmancp.asp修改后的代码。

<!--#include file="../conn/conn.asp" -->
<!--#include file="upload.inc"-->
<%'on error resume next%>
<%
dim upload,file,formName,formPath,iCount,filename,fileExt,i
set upload=new upload_5xSoft '建立上传对象
id=upload.Form("id")
photointro=HTMLEncode2(upload.form("content2"))
name=upload.form("name")
formPath=upload.form("filepath")
classid=upload.form("classid")
'在目录后加(/)
if right(formPath,1)<>"/" then formPath=formPath&"/"
iCount=0
Uperror=0 '定义保存错误变量

for each formName in upload.file '列出所有上传了的文件
set file=upload.file(formName) '生成一个文件对象

if file.filesize<0 then
' response.redirect "error.asp?errid=4"
' response.end
Uperror=1 '如果图片大小出错,错误代码为1
end if
if file.filesize>2000000 then
' response.redirect "error.asp?errid=6"
' response.end
Uperror=1 '如果图片大小出错,错误代码为1
end if

fileExt=lcase(right(file.filename,4))
if fileEXT<>".gif" and fileEXT<>".jpg" and fileEXT<>".png" then
' response.redirect "error.asp?errid=7"
' response.end
Uperror=2 '如果图片格式错误,错误代码为2
end if

if Uperror=0 then '如果错误代码正常,则进行文件上传

filenamett=file.FileName
filenamet=year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&file.FileName
filename=formPath&filenamet

filesize=file.filesize
if file.FileSize>0 then '如果 FileSize > 0 说明有文件数据
file.SaveAs Server.mappath(filename) '保存文件
iCount=iCount+1
end if

set file=nothing

FilePath=Server.MapPath(".")
FilePath=FilePath & "\paladin\"
Set Jpeg = Server.CreateObject("Persits.Jpeg")
Jpeg.Open (FilePath & filenamet)

'开始变更所有文件扩展名为jpg
filenamelen=len(filenamet)
filenamelen=filenamelen-4
filenamet1=filenamet
filenamet=left(filenamet,filenamelen)
filenamet=filenamet&".jpg"
'结束文件名变更

'开始判断哪边为长边,以长边进行缩放
imgWidth=Jpeg.OriginalWidth
imgHeight=Jpeg.OriginalHeight

if imgWidth>=imgHeight and imgWidth>120 then
Jpeg.Width=150
Jpeg.Height=Jpeg.OriginalHeight/(Jpeg.OriginalWidth/150)
end if
if imgHeight>imgWidth and imgHeight>113 then
Jpeg.Height=113
Jpeg.Width=Jpeg.OriginalWidth/(Jpeg.OriginalHeight/113)
end if

Jpeg.Sharpen 1, 130
Jpeg.Save (FilePath & "small_" & filenamet)
'写入数据库
yy=year(date)
mm=right("00"&month(date),2)
dd=right("00"&day(date),2)
idate=yy & "-" & mm & "-" & dd & " "

xx=right("00"&hour(time),2)
ff=right("00"&minute(time),2)
mm=right("00"&second(time),2)
itime=xx & ":" & ff & ":" & mm

itime=idate&itime

photourlb=formPath & filenamet1
'if imgwidth<320 and imgheight<240 then
photourls=formPath & "small_" & filenamet
end if

set rs=server.CreateObject("ADODB.RecordSet")
sql="select * from propic where id="&clng(id)
rs.open sql,conn,1,3
rs("name")=name
rs("photointro")=photointro
if Uperror=0 then '如果图片上传不出错,则更新相应的数据库字段。
rs("imgh")=imgheight
rs("imgw")=imgwidth
rs("filesize")=filesize
rs("url")=photourlb
rs("surl")=photourls
end if
rs("classid")=classid
rs.update
next

set upload=nothing '删除对象

if Uperror=0 then

response.write "<SCRIPT language=JavaScript>alert('文件上传成功,返回!');"
response.write "history.go(-1);</SCRIPT>"
else

response.write "<SCRIPT language=JavaScript>alert('内容修改成功,但并未修改产品图片,返回!');"
response.write "history.go(-1);</SCRIPT>"
end if

function HTMLEncode2(fString)
fString = Replace(fString, CHR(13), "")
fString = Replace(fString, CHR(10) & CHR(10), "</P><P>")
fString = Replace(fString, CHR(10), "<BR>")
HTMLEncode2 = fString
end function
%>
lzp4881 2009-11-03
  • 打赏
  • 举报
回复
if file.filesize <=0 then
exit for'这里打错了
'response.redirect "error.asp?errid=4"
'response.end
end if
lzp4881 2009-11-03
  • 打赏
  • 举报
回复
你把
if file.filesize<0 then
response.redirect "error.asp?errid=4"
response.end
end if
改成
if file.filesize<=0 then
exit fox
'response.redirect "error.asp?errid=4"
'response.end
end if
yoyoyuye 2009-11-03
  • 打赏
  • 举报
回复
当没有对图片进行编辑,提示“图片格式”错误,就是
fileExt=lcase(right(file.filename,4))
if fileEXT<>".gif" and fileEXT<>".jpg" and fileEXT<>".png" then
response.redirect "error.asp?errid=7"
response.end
end if

这段代码啦。我对图片进行了替换,就可以通过,没替换。就转到上面的页面,说格式不对
lzp4881 2009-11-03
  • 打赏
  • 举报
回复
报什么错?

28,408

社区成员

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

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