大文件分段上传
来源:互联网 发布:unity麻将源码 编辑:程序博客网 时间:2024/05/20 11:23
の吟清手记
一段方便的ASP无组件上传程序
我最近在做一个商品发布系统需要上传商品图片,虽然以前也写过一个采用无组件上传的图片上传程序,但是过了这么久代码都找不到了(PS:习惯不太好,没有整理代码的习惯,呵呵!!!)还要重新写我当然没有这么笨了,当然是去网上盗了。 [lol]
我从网上下载一个商城系统得到这样几个页面是上传图片的,我精简了一下,现在发布供大家参考。
up.asp
建立一个上传图片的文件夹uploadfiles
<!--
=================== Aspid =======================
http://www.aspid.cn/
Author: 吟清
Last Update: 2005-07-04
===============================================
-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>ASPid - 上传图片</title>
</head>
<body><form name="formname" method="post" action="saveaddbook.asp?action=add" OnSubmit="return checkkk()" >
<input name="upfile" type="text" id="upfile" size="30">
<input name="upbtn" type="button" id="upbtn" onClick="window.open('upload.asp?formname=formname&editname=upfile&uppath=uploadfiles&filelx=jpg','','status=no,scrollbars=no,top=20,left=110,width=420,height=165')" value="上传图片">
</form>
</body>
</html>
upload.asp
uppath=request("uppath")&"/" '文件上传路径
filelx=request("filelx") '文件上传类型
formName=request("formName") '回传到上页面编辑框所在Form的Name
EditName=request("EditName") '回传到上页面编辑框的Name
%>
<html><head><title>ASPid - 图片上传</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<script language="javascript">
<!--
function mysub()
{
esave.style.visibility="visible";
}
-->
</script>
</head>
<body>
<form name="form1" method="post" action="upfile.asp" enctype="multipart/form-data" >
<div id="esave" style="position:absolute; top:18px; left:40px; z-index:10; visibility:hidden">
<TABLE WIDTH=340 BORDER=0 CELLSPACING=0 CELLPADDING=0>
<TR><td width=20%></td>
<TD bgcolor=#003366 width="60%">
<TABLE WIDTH=100% height=100 BORDER=0 CELLSPACING=1 CELLPADDING=0>
<TR>
<td bgcolor=#ffffff align=center><font color=#003366>正在上传文件,请稍候...</font></td>
</tr>
</table>
</td><td width=20%></td>
</tr></table></div>
<table class="tableBorder" width="90%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td align="center" bgcolor="#003366"><b><font color="#ffffff">图片上传
<input type="hidden" name="filepath" value="<%=uppath%>">
<input type="hidden" name="filelx" value="<%=filelx%>">
<input type="hidden" name="EditName" value="<%=EditName%>">
<input type="hidden" name="FormName" value="<%=formName%>">
<input type="hidden" name="act" value="uploadfile">
</font></b> </td>
</tr>
<tr bgcolor="#E8F1FF">
<td align="center" id="upid" height="80">选择文件:
<input type="file" name="file1" size="40" class="tx1" value="">
<input type="submit" name="Submit" value="开始上传" class="button" onclick="javascript:mysub()">
</td>
</tr>
</table>
</form>
</body>
</html>
upfile.asp
<%
set upload=new upload_file
if upload.form("act")="uploadfile" then
filepath=trim(upload.form("filepath"))
filelx=trim(upload.form("filelx"))
i=0
for each formName in upload.File
set file=upload.File(formName)
fileExt=lcase(file.FileExt) '得到的文件扩展名不含有.
if file.filesize<100 then
response.write "<script language=javascript>alert('请先选择你要上传的文件!');history.go(-1);</script>"
response.end
end if
if (filelx<>"swf") and (filelx<>"jpg") then
response.write "<script language=javascript>alert('该文件类型不能上传!');history.go(-1);</script>"
response.end
end if
if filelx="swf" then
if fileext<>"swf" then
response.write "<script language=javascript>alert('只能上传swf格式的Flash文件!');history.go(-1);</script>"
response.end
end if
end if
if filelx="jpg" then
if fileext<>"gif" and fileext<>"jpg" then
response.write "<script language=javascript>alert('只能上传jpg或gif格式的图片!');history.go(-1);</script>"
response.end
end if
end if
if filelx="swf" then
if file.filesize>(3000*1024) then
response.write "<script language=javascript>alert('Flash文件大小不能超过3m!');history.go(-1);</script>"
response.end
end if
end if
if filelx="jpg" then
if file.filesize>(1000*1024) then
response.write "<script language=javascript>alert('图片文件大小不能超过1m!');history.go(-1);</script>"
response.end
end if
end if
randomize
ranNum=int(90000*rnd)+10000
filename=filepath&year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&ranNum&"."&fileExt
%>
<%
if file.FileSize>0 then ''如果 FileSize > 0 说明有文件数据
'file.SaveAs Server.mappath(filename) ''保存文件
file.SaveToFile Server.mappath(FileName)
'response.write file.FileName&" 上传成功! <br>"
'response.write "新文件名:"&FileName&"<br>"
'response.write "新文件名已复制到所需的位置,可关闭窗口!"
if filelx="swf" then
response.write "<script>window.opener.document."&upload.form("FormName")&".size.value='"&int(file.FileSize/1024)&" K'</script>"
end if
response.write "<script>window.opener.document."&upload.form("FormName")&"."&upload.form("EditName")&".value='"&FileName&"'</script>"
%>
<%
end if
set file=nothing
next
set upload=nothing
end if
%>
<script language="javascript">
window.alert("文件上传成功!");
window.close();
</script>
最后一个upload.inc是一个无组件上传
'----------------------------------------------------------------------
'转发时请保留此声明信息,这段声明不并会影响你的速度!
'******************* 无组件上传类 ********************************
'修改者:梁无惧
'原作者:稻香老农
'文件属性:例如上传文件为c:/myfile/doc.txt
'FileName 文件名 字符串 "doc.txt"
'FileSize 文件大小 数值 1210
'FileType 文件类型 字符串 "text/plain"
'FileExt 文件扩展名 字符串 "txt"
'FilePath 文件原路径 字符串 "c:/myfile"
'使用时注意事项:
'由于Scripting.Dictionary区分大小写,所以在网页及ASP页的项目名都要相同的大小
'写,如果人习惯用大写或小写,为了防止出错的话,可以把
'sFormName = Mid (sinfo,iFindStart,iFindEnd-iFindStart)
'改为
'(小写者)sFormName = LCase(Mid (sinfo,iFindStart,iFindEnd-iFindStart))
'(大写者)sFormName = UCase(Mid (sinfo,iFindStart,iFindEnd-iFindStart))
'**********************************************************************
'----------------------------------------------------------------------
dim oUpFileStream
Class upload_file
dim Form,File,Version
Private Sub Class_Initialize
'定义变量
dim RequestBinDate,sStart,bCrLf,sInfo,iInfoStart,iInfoEnd,tStream,iStart,oFileInfo
dim iFileSize,sFilePath,sFileType,sFormvalue,sFileName
dim iFindStart,iFindEnd
dim iFormStart,iFormEnd,sFormName
'代码开始
Version="无组件上传类 Version 0.96"
set Form = Server.CreateObject("Scripting.Dictionary")
set File = Server.CreateObject("Scripting.Dictionary")
if Request.TotalBytes < 1 then Exit Sub
set tStream = Server.CreateObject("adodb.stream")
set oUpFileStream = Server.CreateObject("adodb.stream")
oUpFileStream.Type = 1
oUpFileStream.Mode = 3
oUpFileStream.Open
oUpFileStream.Write Request.BinaryRead(Request.TotalBytes)
oUpFileStream.Position=0
RequestBinDate = oUpFileStream.Read
iFormEnd = oUpFileStream.Size
bCrLf = chrB(13) & chrB(10)
'取得每个项目之间的分隔符
sStart = MidB(RequestBinDate,1, InStrB(1,RequestBinDate,bCrLf)-1)
iStart = LenB (sStart)
iFormStart = iStart+2
'分解项目
Do
iInfoEnd = InStrB(iFormStart,RequestBinDate,bCrLf & bCrLf)+3
tStream.Type = 1
tStream.Mode = 3
tStream.Open
oUpFileStream.Position = iFormStart
oUpFileStream.CopyTo tStream,iInfoEnd-iFormStart
tStream.Position = 0
tStream.Type = 2
tStream.Charset ="gb2312"
sInfo = tStream.ReadText
'取得表单项目名称
iFormStart = InStrB(iInfoEnd,RequestBinDate,sStart)-1
iFindStart = InStr(22,sInfo,"name=""",1)+6
iFindEnd = InStr(iFindStart,sInfo,"""",1)
sFormName = Mid (sinfo,iFindStart,iFindEnd-iFindStart)
'如果是文件
if InStr (45,sInfo,"filename=""",1) > 0 then
set oFileInfo= new FileInfo
'取得文件属性
iFindStart = InStr(iFindEnd,sInfo,"filename=""",1)+10
iFindEnd = InStr(iFindStart,sInfo,"""",1)
sFileName = Mid (sinfo,iFindStart,iFindEnd-iFindStart)
oFileInfo.FileName = GetFileName(sFileName)
oFileInfo.FilePath = GetFilePath(sFileName)
oFileInfo.FileExt = GetFileExt(sFileName)
iFindStart = InStr(iFindEnd,sInfo,"Content-Type: ",1)+14
iFindEnd = InStr(iFindStart,sInfo,vbCr)
oFileInfo.FileType = Mid (sinfo,iFindStart,iFindEnd-iFindStart)
oFileInfo.FileStart = iInfoEnd
oFileInfo.FileSize = iFormStart -iInfoEnd -2
oFileInfo.FormName = sFormName
file.add sFormName,oFileInfo
else
'如果是表单项目
tStream.Close
tStream.Type = 1
tStream.Mode = 3
tStream.Open
oUpFileStream.Position = iInfoEnd
oUpFileStream.CopyTo tStream,iFormStart-iInfoEnd-2
tStream.Position = 0
tStream.Type = 2
tStream.Charset = "gb2312"
sFormvalue = tStream.ReadText
form.Add sFormName,sFormvalue
end if
tStream.Close
iFormStart = iFormStart+iStart+2
'如果到文件尾了就退出
loop until (iFormStart+2) = iFormEnd
RequestBinDate=""
set tStream = nothing
End Sub
Private Sub Class_Terminate
'清除变量及对像
if not Request.TotalBytes<1 then
oUpFileStream.Close
set oUpFileStream =nothing
end if
Form.RemoveAll
File.RemoveAll
set Form=nothing
set File=nothing
End Sub
'取得文件路径
Private function GetFilePath(FullPath)
If FullPath <> "" Then
GetFilePath = left(FullPath,InStrRev(FullPath, "/"))
Else
GetFilePath = ""
End If
End function
'取得文件名
Private function GetFileName(FullPath)
If FullPath <> "" Then
GetFileName = mid(FullPath,InStrRev(FullPath, "/")+1)
Else
GetFileName = ""
End If
End function
'取得扩展名
Private function GetFileExt(FullPath)
If FullPath <> "" Then
GetFileExt = mid(FullPath,InStrRev(FullPath, ".")+1)
Else
GetFileExt = ""
End If
End function
End Class
'文件属性类
Class FileInfo
dim FormName,FileName,FilePath,FileSize,FileType,FileStart,FileExt
Private Sub Class_Initialize
FileName = ""
FilePath = ""
FileSize = 0
FileStart= 0
FormName = ""
FileType = ""
FileExt = ""
End Sub
'保存文件方法
Public function SaveToFile(FullPath)
dim oFileStream,ErrorChar,i
SaveToFile=1
if trim(fullpath)="" or right(fullpath,1)="/" then exit function
set oFileStream=CreateObject("Adodb.Stream")
oFileStream.Type=1
oFileStream.Mode=3
oFileStream.Open
oUpFileStream.position=FileStart
oUpFileStream.copyto oFileStream,FileSize
oFileStream.SaveToFile FullPath,2
oFileStream.Close
set oFileStream=nothing
SaveToFile=0
end function
End Class
%>
这个梁无惧修改的0.96化境编程界无组件上传类,大家可千万不要使用这个版本的。
旧版本的无组件上传中有很大的漏洞,给黑客上传“木马”、“病毒”开了方便之门,问题主要是出在电脑不能正确判断含有“/0”二进制字符文件名或路径,可以本地抓包嗅探流文件并用二进制编辑器伪装IP包通过网络军刀上传,你使用这样的上传类等于是给黑客开了后门.
一定要去下载新的上传类,无惧无组件上传类已经更新到2.2版本了,网上还有流行的先锋无组件上传类(杜绝上传漏洞版),你去下载下试试,再稍加修改这几段程序就可以使用了。
请尊重作者劳动成果,转载本文必须遵循“署名-非商业用途-保持一致”的创作共用协议.
This Article is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License.
- 谈点想法:Asp学习者选看-Asp初学者提纲
- 谈点想法:Asp学习者选看-对Asp入门者的建议
- 如何确保应用系统的安全
- Response对象的使用详解
- 超强:单文件的ASP文章管理系统
完整代码列表
WebForm1.aspx
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="CSharpUpload.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name=vs_defaultClientScript content="JavaScript">
<meta name=vs_targetSchema content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" enctype="multipart/form-data" runat="server">
<INPUT type=file id=File1 name=File1 runat="server" >
<br/>
<input type="submit" id="Submit1" value="Upload" runat="server" NAME="Submit1">
</form>
</body>
</HTML>
WebForm1.aspx.cs
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace CSharpUpload
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.HtmlControls.HtmlInputFile File1;
protected System.Web.UI.HtmlControls.HtmlInputButton Submit1;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Submit1.ServerClick += new System.EventHandler(this.Submit1_ServerClick);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void Submit1_ServerClick(object sender, System.EventArgs e)
{
if( ( File1.PostedFile != null ) && ( File1.PostedFile.ContentLength > 0 ) )
{
string fn = System.IO.Path.GetFileName(File1.PostedFile.FileName);
string SaveLocation = Server.MapPath("Data") + "//" + fn;
try
{
File1.PostedFile.SaveAs(SaveLocation);
Response.Write("The file has been uploaded.");
}
catch ( Exception ex )
{
Response.Write("Error: " + ex.Message);
}
}
else
{
Response.Write("Please select a file to upload.");
}
}
}
}
软件资讯 ┆硬件资讯 ┆动漫频道 ┆游戏下载 ┆数码软件 ┆硬件报价 ┆电脑技巧 ┆DIY 天地 广告联系 版权说明 网友投稿 意见建议 加入收藏 设为首页 资讯首页 ┆软件新闻 ┆网络动态 ┆信息安全 ┆软件评测 ┆软件技巧 ┆编程开发 ┆设计教程 ┆教学动画 ┆游戏娱乐 ┆专题 8 您的位置: 首页→ 编程开发→ 网络编程→ ASP→ 正文 利用 xmlhttp 分块上传文件 发布日期: 2005-11-10 9:30:39 作者: 不详 字体:【大 中 小】【打印本页】
编写思路:把本地文件在客户端通过base64编码以后发送目的地.
测试过程中,上传文件过大,导致超时不成功.
后来经过改善.把编码分段发送.测试20M成功
编写目的:在传统的解决方案里面,一次一次选取上传可以.但是在碰到把数据库里文件路径读出来,并把这些文件上传到一个地方的时候就比较麻烦.
如果得到路径一个一个去找到用ftp当然也是可以的,但每次找这些文件我看都会比较费时。这里编写这个主要就是为了通过数据库里的文件路径取得文件.把文件一次批量上传到一个地方.
其主要目的还是为了锻炼一下自己.
解决过程:起初试着用模拟键盘输入强行赋值给file控件用传统的方法上传。可是老碰到空值的情况,以至有很多文件没有发送出去。查阅一些资料,现在是把所有路径通过数据库取到然后写到一个js里。然后在前台用js读取这些路径,通过xmlhttp来发送文件。
因为ie不太喜欢xmlHttp.总认为他有恶意行为.所以老谈出提示警告.所以操作的时候不能使用web路径.只能用物理路径去访问它.
然后服务端有一文件来接收这些编码,并对其进行解码.所以我称之为"c/s". ^_^
目前很多代码还在完善中.
简单介绍一下:
aryFiles.push("c://aaa.zip") ;
aryFiles.push("c://bbb.exe") ;
这里为文件路径和文件.可为多个
以后这个路径也可以通过file控件在客户端取到
http:// www.xxx.com/xxx/xxx.asp
这个是目的地,可以改为自己想要的地址.
ado_stream.LoadFromFile(server.mappath(".") &"/"& + str_filename)
server.mappath(".") &"/"& + str_filename 这里是读取文件.
server.mappath(".") &"/"& 路径和存放路径一致
ado_stream.SaveToFile server.mappath(".") &"/"& str_filename,2
server.mappath(".") &"/"& 这个为存放文件的路径. str_filename 为文件名
这里读取和存放都是放在程序所放目录中.大家测试的时候也可以保持这样即可
把第一段代码放到本地(eg:c:/upload.htm)
把第二段代码放到服务器上,可以是本地服务器,可以是公网服务器.和上面的目的地保持一致
(eg:http://www.xxx.com/upload.asp or http:// localhost/www/upload.asp)
操作:找到第一段代码保存的地方。执行即可(eg:打开c盘执行upload.htm)
目前程序还在调试过程中,希望大家提出宝贵意见
客户端代码
<head>
</head>
<body> <input type=button onclick="BeginSendFiles();"
value="发送" /> <input type=button onclick="JavaScript:
Breaked=true;" value="中断" /> <div id="ddd"
width=300px></div> <br></br> <DIV
id=div_message></DIV>
</body>
<script language=VBScript>
Function bytes2BSTR(vIn)
strReturn =""
For i = 1 To LenB(vIn)
ThisCharCode = AscB(MidB(vIn,i,1))
If ThisCharCode < &H80 Then
strReturn = strReturn & Chr(ThisCharCode)
Else
NextCharCode = AscB(MidB(vIn,i+1,1))
strReturn = strReturn & Chr(CLng(ThisCharCode) * &H100 + CInt(NextCharCode))
i = i + 1
End If
Next
bytes2BSTR = strReturn
End Function
</script>
<script language=javascript> var xmlhttp ; var ado_stream ; var
mFileName, mPartStart, mPartID, mPartEnd ; var SendCount ; var
BlockSize ; var Breaked ; var aryFiles ; BlockSize = 1024*100
;//每次发送字节数 Breaked = false ; aryFiles = new Array() ; // 开始发送文件
function BeginSendFiles() { initAryFiles() ; SendFile(aryFiles.pop()) ;
} // 构造待发送文件的数组 function initAryFiles() { aryFiles.push("c://aaa.zip")
; aryFiles.push("c://bbb.exe") ; c://aaa.zip c://bbb.exe本地文件
aryFiles.reverse() ;//文件名 } function SendFile(vFullPath) { // 空文件则不执行上传
if (!vFullPath) { return ; } Breaked = false ; div_message.innerHTML =
"" ; ado_stream = new ActiveXObject("ADODB.Stream"); // 读取文件的流
ado_stream.Type = 1; ado_stream.Open();
ado_stream.LoadFromFile(vFullPath); // 读取文件 ado_stream.position = 0 ;
SendCount = Math.ceil(ado_stream.size/BlockSize) ; // 如果有余数则多发送一次 //
alert(SendCount) ; var reg = //b/w+./w+$/gi mFileName =
reg.exec(vFullPath) ; mPartStart = true ; mPartID = 1 ; mPartEnd =
false ; SendData() ; } function SendData() { if (SendCount > 0) {
var dom = new ActiveXObject("msxml2.DOMDocument"); // 发送的xml文件
dom.async = false; dom.resolveExternals = false; // 构造xml文件头 var node =
dom.createProcessingInstruction("xml","version='1.0'");
dom.appendChild(node) ; node = null ; // 构造root节点 var root =
dom.createElement("root"); dom.appendChild(root) ;
dom.documentElement.setAttribute("xmlns:dt",
"urn:schemas-microsoft-com:datatypes"); // 构造保存二进制数据的节点updata node =
dom.createElement("upData") ; node.dataType = "bin.base64" ; //
bin。base64编码 var att = dom.createAttribute("FileName") ; // 文件名属性
att.value = mFileName ; node.setAttributeNode(att) ; att = null ; var
att = dom.createAttribute("PartStart") ; // 分段开始标记 att.value =
mPartStart ; node.setAttributeNode(att) ; att = null ; var att =
dom.createAttribute("PartID") ; // 分段序号 att.value = mPartID ;
node.setAttributeNode(att) ; att = null ; var att =
dom.createAttribute("PartEnd") ; // 分段结束标记 att.value = mPartEnd ;
node.setAttributeNode(att) ; att = null ; root.appendChild(node) ;
node.nodeTypedValue = ado_stream.Read(BlockSize); // 节点数据从stream读取,固定长度
node = null ; SendCount -= 1 ; xmlhttp = new
ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.open("POST","http://www.xxx.com/xxx/xxx.asp", false);
http://www.xxx.com/xxx/xxx.asp 为web路径上的文件 xmlhttp.onreadystatechange=
CallBack ; xmlhttp.send(dom); mPartStart = false ; xmlhttp = null ; }
else { ado_stream.Close(); ado_stream = null ; } } function CallBack()
{ // 上传成功 if(xmlhttp.readystate == 4) { // 检查是否中断上传 if(Breaked) {
return ; } if (SendCount > 0) { mPartID += 1 ; //
div_message.innerHTML += ("<br>" + xmlhttp.ResponseText) ; var p
= Math.floor((mPartID/(Math.ceil(ado_stream.size/BlockSize) + 1)) *
100) ; // 计算进度百分比 ShowBar(p) ; var t = setTimeout("SendData();", 1) ; }
else { // 传送完文件 div_message.innerHTML += mFileName +
"传送完毕!<br>" ; // 继续传下一文件 ShowBar(0) ; var cFile = aryFiles.pop()
; SendFile(cFile) ; } } } function ShowBar(per) { // 进度条 ddd.innerHTML
= "<table width='200' border=0 cellpadding='0' cellspacing='0'
><tr><td bgcolor='#6699FF'><input type=button style='
width:" + per + "% ; border:0px; background:#005599; color:#FFFFFF'
value=" + per + "%> </td></tr></table>" ; }
</script>
</html>
<% Option Explicit
Response.Expires = 0
' 定义变量和对象。
dim ado_stream
dim xml_dom
dim xml_data
dim str_filename
dim bol_PartStart
dim int_PartID
dim bol_PartEnd
' 创建 Stream 对象
set ado_stream = Server.CreateObject("ADODB.Stream")
' 从Request对象创建 XMLDOM对象
set xml_dom = Server.CreateObject("MSXML2.DOMDocument")
xml_dom.load(request)
' 读出包含二进制数据的节点
set xml_data = xml_dom.selectSingleNode("root/upData")
str_filename = xml_data.getAttribute("FileName")
bol_PartStart = CBool(xml_data.getAttribute("PartStart"))
int_PartID = CInt(xml_data.getAttribute("PartID"))
bol_PartEnd = CBool(xml_data.getAttribute("PartEnd"))
' 打开Stream对象,把数据存入其中
ado_stream.Type = 1 ' 1=adTypeBinary
ado_stream.open
if not bol_PartStart then
ado_stream.LoadFromFile(server.mappath(".") &"/"& + str_filename) ' 读取文件
ado_stream.position = ado_stream.size
end if
ado_stream.Write xml_data.nodeTypedValue
' 文件存盘
ado_stream.SaveToFile server.mappath(".") &"/"& str_filename,2
'保存文件 2=adSaveCreateOverWrite
ado_stream.close
' 释放资源
set ado_stream = Nothing
set xml_dom = Nothing
' 向浏览器返回信息
Response.Write "Upload successful!"& str_filename & int_PartID & bol_PartStart
%>
另外:此文的目的并不是说这个程序能给朋友们解决什么问题,主要目的还是为了和大家交流一些心得:
碰到问题->发现问题->解决问题.
希望大家都不要成为一个标准的代码机器人。
多学、多看、多思考、多实践。
没有什么是不能解决的。
<script type="text/javascript"><!--google_ad_client = "pub-5114532200342862";google_ad_width = 468;google_ad_height = 60;google_ad_format = "468x60_as";google_ad_type = "text";google_ad_channel ="";google_color_border = "FFFFFF";google_color_link = "0000FF";google_color_bg = "FFFFFF";google_color_text = "000000";google_color_url = "008000";//--></script> <script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"></script> <iframe name="google_ads_frame" marginwidth="0" marginheight="0" src="http://pagead2.googlesyndication.com/pagead/ads?client=ca-pub-5114532200342862&dt=1164830243328&lmt=1164830243&format=468x60_as&output=html&url=http%3A%2F%2Fnews.newhua.com%2Fhtml%2FAsp%2F2005-11%2F10%2F05111009500123988_20.shtml&color_bg=FFFFFF&color_text=000000&color_link=0000FF&color_url=008000&color_border=FFFFFF&ad_type=text&ref=http%3A%2F%2Fwww.google.com%2Fsearch%3Fhl%3Dzh-CN%26newwindow%3D1%26q%3D.net%2B%2B%2B%25E5%25A4%25A7%25E6%2596%2587%25E4%25BB%25B6%25E5%2588%2586%25E6%25AE%25B5%25E4%25B8%258A%25E4%25BC%25A0%26btnG%3D%25E6%2590%259C%25E7%25B4%25A2%26lr%3Dlang_zh-CN&cc=175&u_h=800&u_w=1280&u_ah=772&u_aw=1280&u_cd=32&u_tz=480" frameborder="0" width="468" scrolling="no" height="60" allowtransparency="allowtransparency"></iframe>
本站收录
上一篇: 温故知新:几个经典的ASP应用
下一篇: 教你一次下载网页中的所有资源 相关文章 相关软件 ·ASP.NET 2.0服务器控件开发之基本概念篇 ·用ASP.Net实现文件在线压缩和解压缩 ·Kaspersky安全软件发布6.0正式版 ·实例分析 ASP上传漏洞入侵实战及扩展 ·ASP.NET 2.0客户端回调的实现分析 ·新手必看 ASP.NET编程入门随想之信客 ·ASP.NET1.0升级ASP.NET2.0问题总结 ·在Dreamweaver中构建ASP.net开发环境 ·Asp.net 1.0 升级至 ASP.NET 2.0十个问题总 ·Kaspersky反病毒个人专业版更新了! ·Kaspersky Anti-Virus 日病毒码05.20 ·春浪考试系统asp版 3.60 ·Kaspersky Anti-Virus 周病毒库05.18 ·Kaspersky Anti-Virus 累计病毒库05.18 ·Kaspersky Anti-Virus Personal 6.0.1.314 ·Kaspersky Internet Security 6.0.1.314 ·Kaspersky Internet Security 6.0.0.299 汉化版 ·ASProtect 2.3 build 04.26 Beta 汉化版 ·Kaspersky Antivirus 6.0.1.312 Beta 汉化版 ·Flash2ASP 1.3 8 精品推荐
- 大文件分段上传
- 大文件的分段上传
- Web Service 分段上传大文件
- C# 大文件分段上传,下载
- js大文件分段上传并获取文件md5
- 原生java http方式上传大文件(含 文件流分段上传问题、base64分段转码问题解决思路)
- Spring中的分段文件上传
- 原生java http方式上传大文件(含 文件流分段上传问题、base64分段转码问题解决思路)(转)
- 安卓分段上传文件、视频
- plupload分段上传文件,struts2后台接收
- 实现 Amazon S3 数据(文件)分段上传
- 如何将一个大文件分段读取
- C# 分段读取大容量文件
- Silverlight+WCF上传文件(文件分段,百分比进度条显示)
- js 文件的上传 分段读取文件 FileReader
- HTML5 文件域+FileReader 分段读取文件并上传-WebSocket
- 大文件上传研究
- webservice上传大文件
- Oracle数据导入导出imp/exp
- 年月日三联动下拉框
- XmlHttp实现无刷新三联动下拉框
- http://www.cnblogs.com/singlepine/category/59670.html
- MailMessage 类
- 大文件分段上传
- 孙强的查询基类,及应用。
- 存储过程之间相互调用
- 哪一条语句能读出MSSQL用户表中的默认值,是否是主键,是否是标识等,明天结帐
- 在 Web.config 文件中配置安全设置
- 在 ASP.NET 2.0 中保护机密数据
- 为 Web 开发支持 XML 的数据解决方案
- oracle inner join
- 精妙SQL语句介绍
例如:
我上传图片时的路径是:
<img src=UploadFiles/200584182625498.jpg>
可是在上传完后路径变为:
<IMG src="http://localhost/UploadFiles/200584175323951.jpg">
我现在想要路径保存为
<IMG src="UploadFiles/200584175323951.jpg">
不知改怎么改动。
希望站长大哥,给小弟指点一二。
http://localhost/UploadFiles/200584175323951.jpg
是绝对路径
而UploadFiles/200584175323951.jpg
是相对路径,
如果你把在本机上测试的程序传上去并打开浏览,
如果可以正常浏览,
图片路径为http://www.yourname.com/UploadFiles/200584175323951.jpg
表示这仍旧是相对路径,不需要修改。
如果还是http://localhost/UploadFiles/200584175323951.jpg这个路径,
那你再提出来,我们一起去解决这个问题。
不好意思,站长在那呀!我有点糊涂不明白!
能教我该怎样做吗!
我把程序按照你说的上传了。图片路径为http://localhost/UploadFiles/200584175323951.jpg
但是我在IIs里把网站的默认IP一改就成了http://192.168.1.66/UploadFiles/200584175323951.jpg
所以十分郁闷!不知道是那段代码实现读取网站名称的!
http://www.blueidea.com/bbs/NewsDetail.asp?id=2130645
和你发表的类似。
现在就是在在web在线编辑框内显示是的绝对路径,怎么把它改为相对路径。
请站长大哥帮我看看,跪求指点迷津!
可是在链接显示图片时图片属性显示链接地址为:http://192.168.1.66/UploadFiles/200584175323951.jpg
这在局域网内浏览可以显示,但是一上公网图片就不能显示。原因是找不到链接的192.168.1.66主机这是当然得了!
我现在就是想让它的链接地址为:
http://UploadFiles/200584175323951.jpg
这样不论公网局域网就能正常显示了。
我想知道读取http://192.168.1.66的这段代码在程序的那个地方这样就好改了。
谢谢!站长大哥的点拨!请您多费心了!
提示错误:
Server.MapPath() error 'ASP 0171 : 80004005'
Missing Path
/dianzishangwu/xrclass23/upload.asp, line 26
The Path parameter must be specified for the MapPath method.
你最好把你出错的代码贴出来。
然后在程序中设计一段获取图片上传路径等信息程序,然后添加到数据库中。就可以了。
有空来我做好的网页瞧瞧吧 www.pzpxd.com
派中派鞋店是你的干的,还是耐品是你服务的公司啊.
试图访问的网页出现问题,无法显示。
--------------------------------------------------------------------------------
请尝试执行下列操作:
单击刷新按钮,或稍后重试。
打开 localhost 主页,然后查找与所需信息相关的链接。
HTTP 错误 500.100 - 内部服务器错误 - ASP 错误
Internet 信息服务
--------------------------------------------------------------------------------
技术信息(用于支持人员)
错误类型:
ADODB.Stream (0x800A0BBC)
写入文件失败。
/up/Upload.Inc, 第 174 行
浏览器类型:
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)
网页:
POST 38790 ??? /up/Upfile.Asp
POST Data:
错误 '80020009'
发生意外。
/iisHelp/common/500-100.asp,行 219
无惧上传类 v2.2
好像又不可以用了!
无法显示网页
试图访问的网页出现问题,无法显示。
--------------------------------------------------------------------------------
请尝试执行下列操作:
单击刷新按钮,或稍后重试。
打开 localhost 主页,然后查找与所需信息相关的链接。
HTTP 错误 500.100 - 内部服务器错误 - ASP 错误
Internet 信息服务
--------------------------------------------------------------------------------
技术信息(用于支持人员)
错误类型:
Microsoft VBScript 运行时错误 (0x800A01FA)
类没有被定义: 'upload_file'
/up/Upfile.Asp, 第 3 行
浏览器类型:
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)
网页:
POST 38790 ??? /up/Upfile.Asp
POST Data:
. . .
时间:
2006年4月24日, 9:46:00
详细信息:
Microsoft 支持
只能重新做了!只量最近时间不够,有空了一定重新改一下,到时你就能看到了!
不好意思哦!!
==========
试图访问的网页出现问题,无法显示。
--------------------------------------------------------------------------------
请尝试执行下列操作:
单击刷新按钮,或稍后重试。
打开 localhost 主页,然后查找与所需信息相关的链接。
HTTP 错误 500.100 - 内部服务器错误 - ASP 错误
Internet 信息服务
--------------------------------------------------------------------------------
技术信息(用于支持人员)
错误类型:
ADODB.Stream (0x800A0BBC)
写入文件失败。
/up/Upload.Inc, 第 174 行
浏览器类型:
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)
网页:
POST 38790 ??? /up/Upfile.Asp
POST Data:
错误 '80020009'
发生意外。
/iisHelp/common/500-100.asp,行 219
我也出现了这个问题,我在根目录下建立了一个uploadfiles文件夹,我的up.asp、upfile.asp、upload.asp、upload.inc文件都在根目录下。请站长帮忙解决以下谢谢。
<input name="imageshow" type="image" width="130" height="98">
里是如何做到的..我改好几处地方了?还是不可以
以下是upfile.asp修改的代理,相信我是没有拼错字等问题的
response.write "<script>window.opener.document."&upload.form("FormName")&"."&upload.form("EditName")&".value='"&FileName&"'</script>"
我加的代码,是这样的吗?
response.write "<script>window.opener.document."&upload.form("FormName")&"."&upload.form("ImageName")&".src='"&FileName&"'</script>"
你检查一下显示方式和数据传递!试试!
我想发我改了代码给你..谢谢
QQ:445178
你的Email也可以..我发给你看...
检查了..就是不可以,希望你可以帮帮忙..
asp还是新学的..不太会...
在吗?
我是Email是 andylife@tom.com
你可以在up.asp修改如下:
在upfile.asp做如下修改就可以了!
希望有高手可以详细解答一下关于文本域传递的方法!
不过还是想知道为何 <input>是不行的..
thanks
会常来的....
有空经常交流,谢谢支持!