注册 登录
编程论坛 ASP技术论坛

[求助]特想解决的问题,类似论坛发图片的做法,请教大家!!

sjzfls 发布于 2007-10-23 16:51, 1207 次点击

问题如下:

我做了一个网页的提交表单add.html,文字提交到数据库中,显示(显示页面xx_qcnews.asp)都没有问题!
现在我想把这个表单做成可以上传图片的,我想要的做法就是类似论坛发帖这样的,在表单中写上图片地址http://www.xxxxxx.xx.gif,点提交后在显示页面就可以显示出图片,而不是图片的地址!!

如下图:

新闻标题 [__大家帮忙做做啊______________]

新闻内容 ______________________________
| 产品展示 |
| |
| http://www.xxxxx.xx.jpg |
| |
| 产品介绍 |
| 很多文字XXXXXXXX |
| http://www.xxxxx.xx.Gif |
| |
| |
|_____________________________|

提交 重置


点击 提交后 表里的图片地址在 显示详细页面(xx_qcnews.asp)中以图片的形式显示,具体该怎么做呢!!!

具体代码:我的显示页面代码 xx_qcnews.asp

<!--#include file="conn.asp"-->
<link href="css/font.css" rel="stylesheet" type="text/css" />
<%
Function HTMLcode(fString)
If Not IsNull(fString) Then
fString = replace(fString, ">", "&gt;")
fString = replace(fString, "<", "&lt;")
fString = replace(fString, "&#", "<I>&#</I>")
fString = Replace(fString, CHR(32), "<I></I> ")
fString = Replace(fString, CHR(9), " ")
fString = Replace(fString, CHR(34), """)
fString = Replace(fString, CHR(39), "&#39;")
fString = Replace(fString, CHR(13), "")
fString = Replace(fString, CHR(10) & CHR(10), "</P><P> ")
fString = Replace(fString, CHR(10), "<BR> ")
HTMLcode = fString
End if
End Function
%>
<%
exec="select * from qcnews where qc_id=" + xid
set rs=server.createobject("adodb.recordset")
rs.open exec,conn,1,1
%>
<table width="790" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="788"><!--#include file="top.html"--></td>
<td width="2" background="images/bgline.GIF"><img src="images/bgline.GIF" width="2" height="2" /></td>
</tr>
</table>

<table width="790" border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="center"><b><%=HTMLcode(rs("qcnews_head"))%></b></td>
<td><%=HTMLcode(rs("qcnews_body")) %></td>
</tr>
<tr>
<td> </td>
</tr>
</table></td>
<td width="2" background="images/bgline.GIF"><img src="images/bgline.GIF" width="2" height="2" /></td>
</tr>
</table>

<table width="790" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="788"><!--#include file="end.html"--></td>
<td width="2" background="images/bgline.GIF"><img src="images/bgline.GIF" width="2" height="2" /></td>
</tr>
</table>

我的提交页面 add.html

<form name="form1" method="post" action="add_save.asp" onsubmit="return checkform()">
<table width="600" border="0" align="center" cellspacing="3">
<tr>
<td width="133">新闻标题</td>
<td width="451" colspan="2"><input name="qcnews_head" type="text" id="qcnews_head" size="60"></td>
</tr>
<tr>
<td valign="top">新闻内容</td>
<td colspan="2"><textarea name="qcnews_body" cols="60" rows="30" id="qcnews_body"></textarea></td>
</tr>
<tr>
<td> </td>
<td colspan="2"> </td>
</tr>
<tr align="center">
<td> </td>
<td width="10">
<input type="submit" name="Submit" value="提交">
</td>
<td width="100">
<input type="reset" name="Submit2" value="重置">
</td>
</tr>
<input type="hidden" name="x" value="1">
</table>
</form>

15 回复
#2
yms1232007-10-23 21:04

如果是上传图片还是使用iframe包含单独的网页,因为文件数据与其他数据冲突。

#3
sjzfls2007-10-24 08:58

不太明白斑竹的意思啊!!

我的问题就是直接复制图片的地址到表单中,点提交后 在显示新闻页面中显示图片,类似论坛这样的 ~

#4
yms1232007-10-24 15:38

论坛使用的是UBB标签来实现的,还有就是可以使用eWebEditor来实现编辑功能。

#5
sjzfls2007-10-25 18:25
用DW做的表单,可以实现UBB标签功能吗??
#6
sjzfls2007-10-27 17:49
大家帮帮忙啊~~~~
#7
tianyu1232007-10-27 18:49

你的意思就是上传图片,然后在指定的页面显示,是吗?

你可以把图片上传到服务器的一个文件夹中,数据库中只储存图片地址。

在需要显示图片的位置,调用图片的路径即可!
#8
yms1232007-10-27 18:55
以下是引用sjzfls在2007-10-25 18:25:24的发言:
用DW做的表单,可以实现UBB标签功能吗??

我一般是直接写代码实现UBB标签。

#9
sjzfls2007-10-28 15:19

斑竹可以看看我的代码吗?给个提示如何更改呢??

#10
sjzfls2007-10-28 15:21
以下是引用tianyu123在2007-10-27 18:49:27的发言:

你的意思就是上传图片,然后在指定的页面显示,是吗?

你可以把图片上传到服务器的一个文件夹中,数据库中只储存图片地址。

在需要显示图片的位置,调用图片的路径即可!

对,我就是这个意思,可是我不知道如何将路径存入数据库(我想直接在表单里写上路径,点提交后在显示页面就显示具体的图片了),然后在显示页面显示图片!

#11
tianyu1232007-10-28 17:33


<input name="photo" type="file" id="photo">

这不是上传图片的文件域吗!

在把路径(这里所谓的路径一般只获取图片名称即可)写如数据库时,需要写一个转换函数,截取图片名称!(这里建议最好

把图片名称替换成当时时间,这样可以避免图片名称重复替换的问题)

[CODE]Function GetFileName(ByVal strFile)
If strFile <> "" Then
GetFileName =year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&mid(strFile,InStrRev(strFile, "."))
Else
GetFileName = ""
End If
End function[/CODE]

在写入数据的页面,这样获取即可:

photo=GetFileName(request.form("photo"))

在需要显示图片的页面,调用存放图片的文件夹加数据库中图片的名称即可!

如: <img src="img/<%=rs("u_photo")%>" alt="照片" width="59" height="66">

#12
sjzfls2007-10-29 16:07

非常感谢 tianyu123

现在我对asp上传图片有了些理解~~ 不过对于我的上传代码,和显示代码,能指点下具体该怎么样添加上您教我的代码呢?

具体代码:我的显示页面代码 xx_qcnews.asp

<!--#include file="conn.asp"-->
<link href="css/font.css" rel="stylesheet" type="text/css" />
<%
Function HTMLcode(fString)
If Not IsNull(fString) Then
fString = replace(fString, ">", "&gt;")
fString = replace(fString, "<", "&lt;")
fString = replace(fString, "&#", "<I>&#</I>")
fString = Replace(fString, CHR(32), "<I></I> ")
fString = Replace(fString, CHR(9), " ")
fString = Replace(fString, CHR(34), """)
fString = Replace(fString, CHR(39), "&#39;")
fString = Replace(fString, CHR(13), "")
fString = Replace(fString, CHR(10) & CHR(10), "</P><P> ")
fString = Replace(fString, CHR(10), "<BR> ")
HTMLcode = fString
End if
End Function
%>
<%
exec="select * from qcnews where qc_id=" + xid
set rs=server.createobject("adodb.recordset")
rs.open exec,conn,1,1
%>
<table width="790" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="788"><!--#include file="top.html"--></td>
<td width="2" background="images/bgline.GIF"><img src="images/bgline.GIF" width="2" height="2" /></td>
</tr>
</table>

<table width="790" border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="center"><b><%=HTMLcode(rs("qcnews_head"))%></b></td>
<td><%=HTMLcode(rs("qcnews_body")) %></td>
</tr>
<tr>
<td> </td>
</tr>
</table></td>
<td width="2" background="images/bgline.GIF"><img src="images/bgline.GIF" width="2" height="2" /></td>
</tr>
</table>

<table width="790" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="788"><!--#include file="end.html"--></td>
<td width="2" background="images/bgline.GIF"><img src="images/bgline.GIF" width="2" height="2" /></td>
</tr>
</table>



我的提交页面 add.html

<form name="form1" method="post" action="add_save.asp" onsubmit="return checkform()">
<table width="600" border="0" align="center" cellspacing="3">
<tr>
<td width="133">新闻标题</td>
<td width="451" colspan="2"><input name="qcnews_head" type="text" id="qcnews_head" size="60"></td>
</tr>
<tr>
<td valign="top">新闻内容</td>
<td colspan="2"><textarea name="qcnews_body" cols="60" rows="30" id="qcnews_body"></textarea></td>
</tr>
<tr>
<td> </td>
<td colspan="2"> </td>
</tr>
<tr align="center">
<td> </td>
<td width="10">
<input type="submit" name="Submit" value="提交">
</td>
<td width="100">
<input type="reset" name="Submit2" value="重置">
</td>
</tr>
<input type="hidden" name="x" value="1">
</table>
</form>

辛苦!!!!

#13
sjzfls2007-10-29 19:57

看了篇文章,有个这样的解释,请朋友们看看有没有思路~~

文章内容如下:

关于图片与文本同存在数据库中的一点思路,

首先,你的表单的类型设为 <FORM ENCTYPE="multipart/form-data"
ACTION="uploadresult.asp" METHOD=POST>

Please choose a picture to upload:
<INPUT NAME="picture" TYPE=FILE ACCEPT="image/*">
<input name="text1" type=text >
</form>
然后在下一页,用分离的办法先分出文本,此时不能用request.form,应变为
FormData = Request.BinaryRead( FormSize )

FormSize = Request.TotalBytes
bnCRLF = chrB( 13 ) & chrB( 10 )
Divider = LEFTB( FormData, INSTRB( FormData, bnCRLF ) - 1 )
DataStart = INSTRB( FormData, bnCRLF & bnCRLF ) + 4
DataEnd = INSTRB( DataStart + 1, FormData, divider ) - DataStart
Response.ContentType = "image/gif"
Response.BinaryWrite MIDB( FormData, DataStart, DataEnd )

这里先分出的是图像
然后在将其二进制转换为文本。

求出大小。

FormSize = Request.TotalBytes
之后用总大小减去刚才求出的大小。得出文本大小。然后用字符串函数得出其值。
最后分别存在数据库中。

注意,此方法不能完成另存为文件。因为Vbscript中的文件对象不能处理二进制格式。(图象事二进制的)
但Vb中可以,所以我们可已利用组件完成以上工作。
我自己使用自己编写的组件,这样即可以完成存为数据库,又可以存位文件。还可以限制大小,文件类型(gif,jpg,Htm,exe)等等,但具体思路代码仍是上面的代码。

#14
sjzfls2007-11-03 16:40
大家有思路吗?给个提示哦~~~~
#15
cainiao1582007-11-04 11:54
Function HTMLcode(fString)
If Not IsNull(fString) Then
fString = replace(fString, ">", "&gt;")
fString = replace(fString, "<", "&lt;")
fString = replace(fString, "&#", "<I>&#</I>")
fString = Replace(fString, CHR(32), "<I></I> ")
fString = Replace(fString, CHR(9), " ")
fString = Replace(fString, CHR(34), """)
fString = Replace(fString, CHR(39), "&#39;")
fString = Replace(fString, CHR(13), "")
fString = Replace(fString, CHR(10) & CHR(10), "</P><P> ")
fString = Replace(fString, CHR(10), "<BR> ")
HTMLcode = fString
End if
End Function

这段代码在很多地方都看到过!我知道是将指定的字符替换,这段函数在什么情况下需要用!! 他和 server.Htmlencode( )有什么不同???
#16
gookee2007-11-05 19:31

用来显示的页面用正则表达式来获取内容中的图片地址 用replace函数进行替换即可

还有一种方法就是用编辑器啦!

1