怎样用asp上传图片?(50分)

  • 主题发起人 主题发起人 smale
  • 开始时间 开始时间
S

smale

Unregistered / Unconfirmed
GUEST, unregistred user!
我正在为公司作电子商务(asp),遇到一个问题,我想将图片上传到服务器的一个目录中,就像
动网论坛中上传图片一样,请问这段代码应该怎样写?
我写的是:
set uploadimg=server.createobject("scripting.filesystemobject")
uploadimg.copyfile 原文件路径,目标文件路径
这段代码在本地服务器的机器上可以上传图片,但从别的机器上上传就出错了,请各位大侠帮帮忙!
 
这是我收藏的:
想一想,还是贴上来,不过做了些版面的更改<font color="#FF3300">用纯ASP代码实现图片上传并存入数据库中</font><br></span>
<span class="Name01">
<font color="#666666">(作者:苏红超 2000年04月26日 11:49)</font></span><br><br>
<span class="content"><!--Internet开发-->
<BR>
用ASP编写网站应用程序时间长了,难免会遇到各式各样的问题,其中
<BR><BR>关于如何上传文件到服务器恐怕是遇见最多的问题了,尤其是上传图片,比如
<BR><BR>你想要在自己的社区里面实现类似网易虚拟社区提供的“每日一星”的功能,
<BR><BR>就要提供给网友上传照片的功能。上传图片文件到服务器可以使用各种免费的
<BR><BR>文件上传组件,使用起来功能虽然很强大,但是由于很多情况下,我们只能使
<BR><BR>用免费的支持ASP的空间或者租用别人的虚拟空间,对于第一种情况,我们
<BR><BR>根本就没有可能来使用文件上传组件;至于第二种情况,我们也要付出不少的
<BR><BR>“银子”才可以。除非你拥有自己的虚拟主机,你就可以随便的在服务器上面
<BR><BR>安装自己所需要的组件,这种情况对于大多数人来说是可望而不可及的。那我
<BR><BR>们就没有办法了吗?呵呵,答案是肯定的(当然是肯定的了,要不然我也没法
<BR><BR>写出这篇文章啊)。下面就让我们一起来使用纯ASP代码来实现图片的上传
<BR><BR>以及保存到数据库的功能(顺便也实现显示数据库中的图片到网页上的功
<BR><BR>能)。
<BR><BR>首先我们先来熟悉一下将要使用的对象方法。我们用来获取上一个页面传
<BR><BR>递过来的数据一般是使用Request对象。同样的,我们也可以使用Request对象
<BR><BR>来获取上传上来的文件数据,使用的方法是Request.BinaryRead()。而我们要从
<BR><BR>数据库中读出来图片的数据显示到网页上面要用到的方法是:
<BR><BR>Request.BinaryWrite()。在我们得到了图片的数据,要保存到数据库中的时候,
<BR><BR>不可以直接使用Insert语句对数据库进行操作,而是要使用ADO的
<BR><BR>AppendChunk方法,同样的,读出数据库中的图片数据,要使用GetChunk方
<BR><BR>法。各个方法的具体语法如下:
<BR><BR>* Request.BinaryRead语法:
<BR><BR>variant = Request.BinaryRead(count)
<BR><BR> 参数
<BR><BR>variant
<BR><BR>返回值保存着从客户端读取到数据。
<BR><BR>count
<BR><BR>指明要从客户端读取的数据量大小,这个值小于或者等于使用方法
<BR><BR>Request.TotalBytes得到的数据量。
<BR><BR>* Request.BinaryWrite语法:
<BR><BR>Request.BinaryWrite data
<BR><BR> 参数
<BR><BR>data
<BR><BR>要写入到客户端浏览器中的数据包。
<BR><BR>* Request.TotalBytes语法:
<BR><BR>variant = Request.TotalBytes
<BR><BR> 参数
<BR><BR>variant
<BR><BR>返回从客户端读取到数据量的字节数。
<BR><BR>* AppendChunk语法
<BR><BR>将数据追加到大型文本、二进制数据 Field 或 Parameter 对象。
<BR><BR>object.AppendChunk Data
<BR><BR>参数
<BR><BR>object Field 或 Parameter 对象
<BR><BR>Data 变体型,包含追加到对象中的数据。
<BR><BR>说明
<BR><BR>使用 Field 或 Parameter 对象的 AppendChunk 方法可将长二进制或字符数
<BR><BR>据填写到对象中。在系统内存有限的情况下,可以使用 AppendChunk 方法对长
<BR><BR>整型值进行部分而非全部的操作。
<BR><BR>* GetChunk语法
<BR><BR>返回大型文本或二进制数据 Field 对象的全部或部分内容 。
<BR><BR>variable = field.GetChunk( Size )
<BR><BR>返回值
<BR><BR>返回变体型。
<BR><BR>参数
<BR><BR>Size 长整型表达式,等于所要检索的字节或字符数。
<BR><BR>说明
<BR><BR>使用 Field 对象的 GetChunk 方法检索其部分或全部长二进制或字符数据。
<BR><BR>在系统内存有限的情况下,可使用 GetChunk 方法处理部分而非全部的长整型
<BR><BR>值。
<BR><BR>GetChunk 调用返回的数据将赋给“变量”。如果 Size 大于剩余的数据,则
<BR><BR>GetChunk 仅返回剩余的数据而无需用空白填充“变量”。如果字段为空,则
<BR><BR>GetChunk 方法返回 Null。
<BR><BR>每个后续的 GetChunk 调用将检索从前一次 GetChunk 调用停止处开始的数
<BR><BR>据。但是,如果从一个字段检索数据然后在当前记录中设置或读取另一个字段
<BR><BR>的值,ADO 将认为已从第一个字段中检索出数据。如果在第一个字段上再次调
<BR><BR>用 GetChunk 方法,ADO 将把调用解释为新的 GetChunk 操作并从记录的起始
<BR><BR>处开始读取。如果其他 Recordset 对象不是首个 Recordset 对象的副本,则
<BR><BR>访问其中的字段不会破坏 GetChunk 操作。
<BR><BR>如果 Field 对象的 Attributes 属性中的 adFldLong 位设置为 True,则可
<BR><BR>以对该字段使用 GetChunk 方法。
<BR><BR>如果在 Field 对象上使用 Getchunk 方法时没有当前记录,将产生错误 3021
<BR><BR>(无当前记录)。
<BR><BR>接下来,我们就要来设计我们的数据库了,作为测试我们的数据库结构如
<BR><BR>下(Access97):
<BR><BR>字段名称    类型    描述
<BR><BR>  id    自动编号   主键值
<BR><BR> img OLE对象   用来保存图片数据 
<BR><BR>
<BR><BR>对于在MS SQL Server7中,对应的结构如下:
<BR><BR>字段名称    类型    描述
<BR><BR>  id     int(Identity) 主键值
<BR><BR> img   image     用来保存图片数据 
<BR><BR>
<BR><BR>现在开始正式编写我们的纯ASP代码上传部分了,首先,我们有一个提
<BR><BR>供给用户的上传界面,可以让用户选择要上传的图片。代码如下
<BR><BR>(upload.htm):
<BR><BR>&amp;lt;html&amp;gt;
<BR><BR> &amp;lt;body&amp;gt;
<BR><BR> &amp;lt;center&amp;gt;
<BR><BR>   &amp;lt;form name=&amp;quot;mainForm&amp;quot;
enctype=&amp;quot;multipart/form-data&amp;quot;
<BR><BR>action=&amp;quot;process.asp&amp;quot;
method=post&amp;gt;
<BR><BR>    &amp;lt;input type=file name=mefile&amp;gt;&amp;lt;br&amp;gt;
<BR><BR>   &amp;lt;input type=submit name=ok value=&amp;quot;OK&amp;quot;&amp;gt;
<BR><BR>   &amp;lt;/form&amp;gt;
<BR><BR> &amp;lt;/center&amp;gt;
<BR><BR> &amp;lt;/body&amp;gt;
<BR><BR>&amp;lt;/html&amp;gt;
<BR><BR>注意代码中黑色斜体的部分,一定要在Form中有这个属性,否则,将无
<BR><BR>法得到上传上来的数据。
<BR><BR>接下来,我们要在process.asp中对从浏览器中获取的数据进行必要的处
<BR><BR>理,因为我们在process.asp中获取到的数据不仅仅包含了我们想要的上传上来
<BR><BR>的图片的数据,也包含了其他的无用的信息,我们需要剔除冗余数据,并将处
<BR><BR>理过的图片数据保存到数据库中,这里我们以Access97为例。具体代
<BR><BR>码如下(process.asp):
<BR><BR>&amp;lt;%
<BR><BR>response.buffer=true
<BR><BR>formsize=request.totalbytes
<BR><BR>formdata=request.binaryread(formsize)
<BR><BR>bncrlf=chrB(13) &amp;amp;
chrB(10)
<BR><BR>divider=leftB(formdata,clng(instrb(formdata,bncrlf))-1)
<BR><BR>datastart=instrb(formdata,bncrlf &amp;amp;
bncrlf)+4
<BR><BR>dataend=instrb(datastart+1,formdata,divider)-datastart
<BR><BR>mydata=midb(formdata,datastart,dataend)
<BR><BR>
<BR><BR>set connGraph=server.CreateObject(&amp;quot;ADODB.connection&amp;quot;)
<BR><BR>connGraph.ConnectionString=&amp;quot;driver={Microsoft Access Driver (*.mdb)};DBQ=&amp;quot;
&amp;amp;
<BR><BR>server.MapPath(&amp;quot;images.mdb&amp;quot;) &amp;amp;
&amp;quot;;uid=;PWD=;&amp;quot;
<BR><BR>connGraph.Open
<BR><BR>
<BR><BR>set rec=server.createobject(&amp;quot;ADODB.recordset&amp;quot;)
<BR><BR>rec.Open &amp;quot;SELECT * FROM [images] where id is null&amp;quot;,connGraph,1,3
<BR><BR>rec.addnew
<BR><BR>rec(&amp;quot;img&amp;quot;).appendchunk mydata
<BR><BR>rec.update
<BR><BR>rec.close
<BR><BR>set rec=nothing
<BR><BR>set connGraph=nothing
<BR><BR>%&amp;gt;
<BR><BR>好了,这下我们就把上传来的图片保存到了名为images.mdb的数据库中
<BR><BR>了,剩下的工作就是要将数据库中的图片数据显示到网页上面了。一般在HT
<BR><BR>ML中,显示图片都是使用&amp;lt;IMG&amp;gt;标签,也就是&amp;lt;IMG SRC=&amp;quot;图片路径&amp;quot;&amp;gt;,但
<BR><BR>是我们的图片是保存到了数据库中,“图片路径”是什么呢?呵呵,其实这个
<BR><BR>SRC属性除了指定路径外,也可以这样使用哦:
<BR><BR>&amp;lt;IMG SRC=&amp;quot;showimg.asp?id=xxx&amp;quot;&amp;gt;
<BR><BR>所以,我们所要做的就是在showimg.asp中从数据库中读出来符合条件的
<BR><BR>数据,并返回到SRC属性中就可以了,具体代码如下(showimg.asp):
<BR><BR>&amp;lt;%
<BR><BR>set connGraph=server.CreateObject(&amp;quot;ADODB.connection&amp;quot;)
<BR><BR>connGraph.ConnectionString=&amp;quot;driver={Microsoft Access Driver (*.mdb)};DBQ=&amp;quot;
&amp;amp;
<BR><BR>server.MapPath(&amp;quot;images.mdb&amp;quot;) &amp;amp;
&amp;quot;;uid=;PWD=;&amp;quot;
<BR><BR>connGraph.Open
<BR><BR>set rec=server.createobject(&amp;quot;ADODB.recordset&amp;quot;)
<BR><BR>strsql=&amp;quot;select img from images where id=&amp;quot;
&amp;amp;
trim(request(&amp;quot;id&amp;quot;))
<BR><BR>rec.open strsql,connGraph,1,1
<BR><BR>Response.ContentType = &amp;quot;image/*&amp;quot;
<BR><BR>Response.BinaryWrite rec(&amp;quot;img&amp;quot;).getChunk(7500000)
<BR><BR>rec.close
<BR><BR>set rec=nothing
<BR><BR>set connGraph=nothing
<BR><BR>%&amp;gt;
<BR><BR>注意在输出到浏览器之前一定要指定Response.ContentType = &amp;quot;image/*&amp;quot;,
<BR><BR>以便正常显示图片。
<BR><BR>最后要注意的地方是,我的process.asp中作的处理没有考虑到第一页
<BR><BR>(upload.htm)中还有其他数据,比如&amp;lt;INPUT type=tesxt name=userid&amp;gt;等等,如果
<BR><BR>有这些项目,你的process.asp就要注意处理掉不必要的数据。
<BR><BR>怎么样,其实上传图片并保存到数据库很简单吧,这样再也不用为自己的
<BR><BR>空间无法使用各类的上传组件发愁了吧。还等什么?赶快试一试吧。
<BR><BR>
<BR><BR>(以上所有程序均在WinNT4.0英文版,IIS4,Access97/MS SQL Server7.0中运

 
上传图片的ASP文件源码[转帖-数字面包]
<%@LANGUAGE="VBSCRIPT"%>
<%
'*** File Upload to: ../temp_img, Extensions: "GIF,JPG,JPEG,BMP,PNG", Form: form1, Redirect: "", "file", "50000", "error"
'*** Pure ASP File Upload Modify Version by xPilot-----------------------------------------------------
' Copyright 2000 (c) George Petrov
'
' Script partially based on code from Philippe Collignon
' (http://www.asptoday.com/articles/20000316.htm)
'
' New features from GP:
' * Fast file save with ADO 2.5 stream object
' * new wrapper functions, extra error checking
' * UltraDev Server Behavior extension
'
' Copyright 2001-2002 (c) Modify by xPilot
' *** Date: 12/15/2001 ***
' *** 支持所有双字节文件名,而且修复了原函数中遇到空格也会自动截断文件名的错误! ***
' *** 保证百分百以原文件名保存上传文件!***
' *** Welcome to visite pilothome.yeah.net or mail xpilot@21cn.com to me!***
'
' Version: 2.0.1 Beta for GB2312,BIG5,Japan,Korea ...
'------------------------------------------------------------------------------
Sub BuildUploadRequest(RequestBin,UploadDirectory,storeType,sizeLimit,nameConflict)
'Get the boundary
PosBeg = 1
PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(13)))
if PosEnd = 0 then
Response.Write "<b>Form was submitted with no ENCTYPE=""multipart/form-data""</b><br>"
Response.Write "Please correct the form attributes and try again."
Response.End
end if
'Check ADO Version
set checkADOConn = Server.CreateObject("ADODB.Connection")
adoVersion = CSng(checkADOConn.Version)
set checkADOConn = Nothing
if adoVersion < 2.5 then
Response.Write "<b>Youdo
n't have ADO 2.5 installed on the server.</b><br>"
Response.Write "The File Upload extension needs ADO 2.5 or greater to run properly.<br>"
Response.Write "You cando
wnload the latest MDAC (ADO is included) from <a href=""www.microsoft.com/data"">www.microsoft.com/data</a><br>"
Response.End
end if
'Check content length if needed
Length = CLng(Request.ServerVariables("HTTP_Content_Length")) 'Get Content-Length header
If "" &amp;
sizeLimit <> "" then
sizeLimit = CLng(sizeLimit)
If Length > sizeLimit then
Request.BinaryRead (Length)
Response.Write "Upload size " &amp;
FormatNumber(Length, 0) &amp;
"B exceeds limit of " &amp;
FormatNumber(sizeLimit, 0) &amp;
"B"
Response.End
End If
End If
boundary = MidB(RequestBin,PosBeg,PosEnd-PosBeg)
boundaryPos = InstrB(1,RequestBin,boundary)
'Get all data inside the boundaries
do
until (boundaryPos=InstrB(RequestBin,boundary &amp;
getByteString("--")))
'Members variable of objects are put in a dictionary object
Dim UploadControl
Set UploadControl = CreateObject("Scripting.Dictionary")
'Get an object name
Pos = InstrB(BoundaryPos,RequestBin,getByteString("Content-Disposition"))
Pos = InstrB(Pos,RequestBin,getByteString("name="))
PosBeg = Pos+6
PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(34)))
Name = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
PosFile = InstrB(BoundaryPos,RequestBin,getByteString("filename="))
PosBound = InstrB(PosEnd,RequestBin,boundary)
'Test if object is of file type
If PosFile<>0 AND (PosFile<PosBound) then
'Get Filename, content-type and content of file
PosBeg = PosFile + 10
PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(34)))
FileName = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
FileName = Mid(FileName,InStrRev(FileName,"/")+1)
'Add filename to dictionary object
UploadControl.Add "FileName", FileName
Pos = InstrB(PosEnd,RequestBin,getByteString("Content-Type:"))
PosBeg = Pos+14
PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(13)))
'Add content-type to dictionary object
ContentType = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
UploadControl.Add "ContentType",ContentType
'Get content of object
PosBeg = PosEnd+4
PosEnd = InstrB(PosBeg,RequestBin,boundary)-2
value = FileName
valueBeg = PosBeg-1
valueLen = PosEnd-Posbeg
else
'Get content of object
Pos = InstrB(Pos,RequestBin,getByteString(chr(13)))
PosBeg = Pos+4
PosEnd = InstrB(PosBeg,RequestBin,boundary)-2
value = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
valueBeg = 0
valueEnd = 0
End If
'Add content to dictionary object
UploadControl.Add "value" , value
UploadControl.Add "valueBeg" , valueBeg
UploadControl.Add "valueLen" , valueLen
'Add dictionary object to main dictionary
UploadRequest.Add name, UploadControl
'Loop to next object
BoundaryPos=InstrB(BoundaryPos+LenB(boundary),RequestBin,boundary)
Loop

GP_keys = UploadRequest.Keys
for GP_i = 0 to UploadRequest.Count - 1
GP_curKey = GP_keys(GP_i)
'Save all uploaded files
if UploadRequest.Item(GP_curKey).Item("FileName") <> "" then
GP_value = UploadRequest.Item(GP_curKey).Item("value")
GP_valueBeg = UploadRequest.Item(GP_curKey).Item("valueBeg")
GP_valueLen = UploadRequest.Item(GP_curKey).Item("valueLen")

if GP_valueLen = 0 then
Response.Write "<B>An error has occured saving uploaded file!</B><br><br>"
Response.Write "Filename: " &amp;
Trim(GP_curPath) &amp;
UploadRequest.Item(GP_curKey).Item("FileName") &amp;
"<br>"
Response.Write "Filedo
es not exists or is empty.<br>"
Response.Write "Please correct and <A HREF=""javascript:history.back(1)"">try again</a>"
response.End
end if

'Create a Stream instance
Dim GP_strm1, GP_strm2
Set GP_strm1 = Server.CreateObject("ADODB.Stream")
Set GP_strm2 = Server.CreateObject("ADODB.Stream")

'Open the stream
GP_strm1.Open
GP_strm1.Type = 1 'Binary
GP_strm2.Open
GP_strm2.Type = 1 'Binary

GP_strm1.Write RequestBin
GP_strm1.Position = GP_valueBeg
GP_strm1.CopyTo GP_strm2,GP_valueLen

'Create and Write to a File
GP_curPath = Request.ServerVariables("PATH_INFO")
GP_curPath = Trim(Mid(GP_curPath,1,InStrRev(GP_curPath,"/")) &amp;
UploadDirectory)
if Mid(GP_curPath,Len(GP_curPath),1) <> "/" then
GP_curPath = GP_curPath &amp;
"/"
end if
GP_CurFileName = UploadRequest.Item(GP_curKey).Item("FileName")
GP_FullFileName = Trim(Server.mappath(GP_curPath))&amp;
"/" &amp;
GP_CurFileName
'Check if the file alreadu exist
GP_FileExist = false
Set fso = CreateObject("Scripting.FileSystemObject")
If (fso.FileExists(GP_FullFileName)) then
GP_FileExist = true
End If
if nameConflict = "error" and GP_FileExist then
Response.Write "<B>File already exists!</B><br><br>"
Response.Write "Please correct and <A HREF=""javascript:history.back(1)"">try again</a>"
GP_strm1.Close
GP_strm2.Close
response.End
end if
if ((nameConflict = "over" or nameConflict = "uniq") and GP_FileExist) or (NOT GP_FileExist) then
if nameConflict = "uniq" and GP_FileExist then
begin
_Name_Num = 0
while GP_FileExist
begin
_Name_Num = begin
_Name_Num + 1
GP_FullFileName = Trim(Server.mappath(GP_curPath))&amp;
"/" &amp;
fso.GetBaseName(GP_CurFileName) &amp;
"_" &amp;
begin
_Name_Num &amp;
"." &amp;
fso.GetExtensionName(GP_CurFileName)
GP_FileExist = fso.FileExists(GP_FullFileName)
wend
UploadRequest.Item(GP_curKey).Item("FileName") = fso.GetBaseName(GP_CurFileName) &amp;
"_" &amp;
begin
_Name_Num &amp;
"." &amp;
fso.GetExtensionName(GP_CurFileName)
UploadRequest.Item(GP_curKey).Item("value") = UploadRequest.Item(GP_curKey).Item("FileName")
end if
on error resume next
GP_strm2.SaveToFile GP_FullFileName,2
if err then
Response.Write "<B>An error has occured saving uploaded file!</B><br><br>"
Response.Write "Filename: " &amp;
Trim(GP_curPath) &amp;
UploadRequest.Item(GP_curKey).Item("FileName") &amp;
"<br>"
Response.Write "Maybe the destination directorydo
es not exist, or youdo
n't have write permission.<br>"
Response.Write "Please correct and <A HREF=""javascript:history.back(1)"">try again</a>"
err.clear
GP_strm1.Close
GP_strm2.Close
response.End
end if
GP_strm1.Close
GP_strm2.Close
if storeType = "path" then
UploadRequest.Item(GP_curKey).Item("value") = GP_curPath &amp;
UploadRequest.Item(GP_curKey).Item("value")
end if
on error goto 0
end if
end if
next

End Sub

'把普通字符串转成二进制字符串函数
Function getByteString(StringStr)
getByteString=""
For i = 1 To Len(StringStr)
XP_varchar = mid(StringStr,i,1)
XP_varasc = Asc(XP_varchar)
If XP_varasc < 0 then

XP_varasc = XP_varasc + 65535
End If

If XP_varasc > 255 then

XP_varlow = Left(Hex(Asc(XP_varchar)),2)
XP_varhigh = right(Hex(Asc(XP_varchar)),2)
getByteString = getByteString &amp;
chrB("&amp;H" &amp;
XP_varlow) &amp;
chrB("&amp;H" &amp;
XP_varhigh)
else

getByteString = getByteString &amp;
chrB(AscB(XP_varchar))
End If
Next
End Function

'把二进制字符串转换成普通字符串函数
Function getString(StringBin)
getString =""
Dim XP_varlen,XP_vargetstr,XP_string,XP_skip
XP_skip = 0
XP_string = ""
If Not IsNull(StringBin) then

XP_varlen = LenB(StringBin)
For i = 1 To XP_varlen
If XP_skip = 0 then
XP_vargetstr = MidB(StringBin,i,1)
If AscB(XP_vargetstr) > 127 then

XP_string = XP_string &amp;
Chr(AscW(MidB(StringBin,i+1,1) &amp;
XP_vargetstr))
XP_skip = 1
else

XP_string = XP_string &amp;
Chr(AscB(XP_vargetstr))
End If
else

XP_skip = 0
End If
Next
End If
getString = XP_string
End Function

Function UploadFormRequest(name)
on error resume next
if UploadRequest.Item(name) then
UploadFormRequest = UploadRequest.Item(name).Item("value")
end if
End Function

'Process the upload
UploadQueryString = Replace(Request.QueryString,"GP_upload=true","")
if mid(UploadQueryString,1,1) = "&amp;" then
UploadQueryString = Mid(UploadQueryString,2)
end if

GP_uploadAction = CStr(Request.ServerVariables("URL")) &amp;
"?GP_upload=true"
If (Request.QueryString <> "") then

if UploadQueryString <> "" then
GP_uploadAction = GP_uploadAction &amp;
"&amp;" &amp;
UploadQueryString
end if
End If

If (CStr(Request.QueryString("GP_upload")) <> "") then
GP_redirectPage = ""
If (GP_redirectPage = "") then
GP_redirectPage = CStr(Request.ServerVariables("URL"))
end if

RequestBin = Request.BinaryRead(Request.TotalBytes)
Dim UploadRequest
Set UploadRequest = CreateObject("Scripting.Dictionary")
BuildUploadRequest RequestBin, "../temp_img", "file", "500000", "error"

'*** GP NO REDIRECT
end if
if UploadQueryString <> "" then
UploadQueryString = UploadQueryString &amp;
"&amp;GP_upload=true"
else

UploadQueryString = "GP_upload=true"
end if


%>
<html>
<head>
<title>上传您的图片</title>
<meta http-equiv="Content-Type" content="text/html;
charset=gb2312">
<link rel="stylesheet" href="../images/css/tz.css" type="text/css">
<script language="javascript">
<!--
function getFileExtension(filePath) { //v1.0
fileName = ((filePath.indexOf('/') > -1) ? filePath.substring(filePath.lastIndexOf('/')+1,filePath.length) : filePath.substring(filePath.lastIndexOf('//')+1,filePath.length));
return fileName.substring(fileName.lastIndexOf('.')+1,fileName.length);
}

function checkFileUpload(form,extensions) { //v1.0
do
cument.MM_returnvalue = true;
if (extensions &amp;&amp;
extensions != '') {
for (var i = 0;
i<form.elements.length;
i++) {
field = form.elements;
if (field.type.toUpperCase() != 'FILE') continue;
if (field.value == '') {
alert('文件框中必须保证已经有文件被选中!');
do
cument.MM_returnvalue = false;field.focus();break;
}
if (extensions.toUpperCase().indexOf(getFileExtension(field.value).toUpperCase()) == -1) {
alert('这种文件类型不允许上传!./n只有以下类型的文件才被允许上传: ' + extensions + './n请选择别的文件并重新上传.');
do
cument.MM_returnvalue = false;field.focus();break;
} } }
}

function MM_goToURL() { //v3.0
var i, args=MM_goToURL.arguments;
document.MM_returnvalue = false;
for (i=0;
i<(args.length-1);
i+=2) eval(args+".location='"+args[i+1]+"'");
}
//-->
</script>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<form name="form1" enctype="multipart/form-data" action="<%=GP_uploadAction%>" onSubmit="checkFileUpload(this,'GIF,JPG,JPEG,BMP,PNG');returndo
cument.MM_returnvalue" method="post">
<table width="350" cellpadding="0" cellspacing="0" border="0" align="center">
<tr>
<td bgcolor="#0099FF">
<table width="100%" border="0" cellspacing="1" cellpadding="4" class="pt9">
<tr bgcolor="#EEEEEE" align="center">
<td colspan="2" class="pt9-000099" height="35"> 上传您的图片</td>
</tr>
<tr bgcolor="#EEEEEE">
<td width="17%" bgcolor="#EEEEEE" align="center">图片</td>
<td width="83%">
<input type="file" name="file" class="txtfld">
</td>
</tr>
<tr bgcolor="#EEEEEE">
<td width="17%"> </td>
<td width="83%">
<input type="submit" value=" 上 传 " class="txtfld4">
<% if request.querystring ("GP_upload") <> "" then
%>
<script>window.opener.form1.f3_content.value+='http://www.dw-mx.com/forum/temp_img/<;%=UploadFormRequest("file")%>';window.close();</script><% end if %>
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</body>
</html>


-----------------------
注意:下面的js做一下说明
<script>window.opener.form1.f3_content.value+='http://www.dw-mx.com/forum/temp_img/<;%=UploadFormRequest("file")%>';window.close();</script>

form1:指将上传的文件名返回原页面的表单名
f3_content:指表单中的控件名
后面的地址是你指定上传的目录,一般要用只要修改这几个地方就可以,记住这个js是针对弹出窗口的上传页面用的,就好比我论坛上的上传图片样子,否则js失效。
 
我只給你個網址,你就會了。。。
不過是要分的。。[:D][:D]
http://www.5xSoft.com/
 
到处都有这样的代码参考
 
后退
顶部