當前位置:首頁 » 文件管理 » asp圖片上傳源碼

asp圖片上傳源碼

發布時間: 2023-03-21 10:09:35

Ⅰ ASP上傳圖片代碼,最簡單的

無懼無組件上傳:
這是放到前面讓選擇圖片的代碼和上傳按鈕 <form action="Upfile_ProctPic.asp?Act=index" method="post" name="form2" onSubmit="return check()" enctype="multipart/form-data">
<input name="FileName" type="FILE" class="tx1" size="22">
<input type="submit" name="Submit1" value="上傳" style="border:1px double rgb(88,88,88);font:9pt">
</form>

這是Upfile_ProctPic.asp文件,修改下存儲路徑和數據表
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><%@language=vbscript codepage=936 %>
<!--#include file="config.asp"-->
<!--#include file="upfile_class.asp"-->
<!--#include virtual="/config/config.asp"-->
<%
picname=Requesta("Act")
const upload_type=0 '上傳方法:0=無懼無組件上傳類,1=FSO上傳 2=lyfupload,3=aspupload,4=chinaaspupload
'const SaveUpProctPicPath="UploadProctPic"
'const UpProctPicType="jpg|gif|png|bmp"
'const MaxProctPicSize=20480000

dim upload,oFile,formName,SavePath,FileName,fileExt,oFileSize
dim EnableUpload
dim arrUpFileType
dim ranNum
dim msg,FoundErr
msg=""
FoundErr=false
EnableUpload=false
SavePath = "upfiles/" '存放上傳文件的目錄
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">

</head>
<body leftmargin="2" topmargin="5" marginwidth="0" marginheight="0">
<%
if EnableUploadFile="No" then
response.write "系統未開放文件上傳功能"
else

select case upload_type
case 0
call upload_0() '使用化境無組件上傳類
case else
'response.write "本系統未開放插件功能"
'response.end
end select

end if
%>
</body>
</html>
<%
sub upload_0() '使用化境無組件上傳類
set upload=new upfile_class ''建立上傳對象
upload.GetData(20480000) '取得上傳數據,限制最大上傳500K
if upload.err > 0 then '如果出錯
select case upload.err
case 1
response.write "請先選擇你要上傳的文件!"
case 2
response.write "你上傳的文件總大小超出了最大限制(20M)"
end select
response.end
end if

for each formName in upload.file '列出所有上傳了的文件
EnableUpload=False
set ofile=upload.file(formName) '生成一個文件對象
oFileSize=ofile.filesize
if oFileSize<10 then
msg="請先選擇你要上傳的文件!!"
FoundErr=True
elseif ofilesize>(MaxProctPicSize*1024) then
msg="文件大小超過了限制,最大隻能上傳" & CStr(MaxProctPicSize) & "K的文件!"
FoundErr=true
end if

fileExt=lcase(ofile.FileExt)
arrUpFileType=split(UpProctPicType,"|")
for i=0 to ubound(arrUpFileType)
if fileEXT=trim(arrUpFileType(i)) then
EnableUpload=true
exit for
end if
next
if fileEXT="asp" or fileEXT="asa" or fileEXT="aspx" or fileEXT="cer" or fileEXT="cdx" then
EnableUpload=false
end if
if EnableUpload=false then
msg="這種文件類型不允許上傳!\n\n只允許上傳這幾種文件類型:" & UpProctPicType
FoundErr=true
end if

strJS="<SCRIPT language=javascript>" & vbcrlf
if FoundErr<>true then
randomize
ranNum=int(900*rnd)+100
FileName="../../"&SavePath&picname&"."&fileExt

ofile.SaveToFile Server.mappath(FileName) '保存文件
conn.open constr
sql="update indexPic set p_picture='"&picname&"."&fileExt&"' where p_name='"&picname&"'"
conn.execute(sql)
conn.close
Alert_reDirect "上傳成功!","indexPic.asp"

end if
next
set upload=nothing
end sub
%>

這是upfile_class.asp文件,不用更改。
<%

Dim oUpFileStream
'----------------------------------------------------------------------
'文件上傳類
Class UpFile_Class

Dim Form,File,Version,Err

Private Sub Class_Initialize
Version = "無懼上傳類 Version V1.2"
Err = -1
End Sub

Private Sub Class_Terminate
'清除變數及對像
If Err < 0 Then
Form.RemoveAll
Set Form = Nothing
File.RemoveAll
Set File = Nothing
oUpFileStream.Close
Set oUpFileStream = Nothing
End If
End Sub

Public Sub GetData (MaxSize)
'定義變數
Dim RequestBinDate,sSpace,bCrLf,sInfo,iInfoStart,iInfoEnd,tStream,iStart,oFileInfo
Dim iFileSize,sFilePath,sFileType,sFormValue,sFileName
Dim iFindStart,iFindEnd
Dim iFormStart,iFormEnd,sFormName
'代碼開始
If Request.TotalBytes < 1 Then '如果沒有數據上傳
Err = 1
Exit Sub
End If
If MaxSize > 0 Then '如果限制大小
If Request.TotalBytes > MaxSize Then
Err = 2 '如果上傳的數據超出限制
Exit Sub
End If
End If
Set Form = Server.CreateObject ("Scripting.Dictionary")
Form.CompareMode = 1
Set File = Server.CreateObject ("Scripting.Dictionary")
File.CompareMode = 1
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)
'取得每個項目之間的分隔符
sSpace = MidB (RequestBinDate,1, InStrB (1,RequestBinDate,bCrLf)-1)
iStart = LenB (sSpace)
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,sSpace)-1
iFindStart = InStr (22,sInfo,"name=""",1)+6
iFindEnd = InStr (iFindStart,sInfo,"""",1)
sFormName = Trim(Mid (sinfo,iFindStart,iFindEnd-iFindStart))
'如果是文件
If InStr (45,sInfo,"filename=""",1) > 0 Then
Set oFileInfo = new FileInfo_Class
'取得文件屬性
iFindStart = InStr (iFindEnd,sInfo,"filename=""",1)+10
iFindEnd = InStr (iFindStart,sInfo,"""",1)
sFileName = Trim(Mid(sinfo,iFindStart,iFindEnd-iFindStart))
oFileInfo.FileName = Mid (sFileName,InStrRev (sFileName, "\")+1)
oFileInfo.FilePath = Left (sFileName,InStrRev (sFileName, "\"))
oFileInfo.FileExt = Mid (sFileName,InStrRev (sFileName, ".")+1)
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
If Form.Exists (sFormName) Then
Form (sFormName) = Form (sFormName) & ", " & sFormValue
else
form.Add sFormName,sFormValue
End If
End If
tStream.Close
iFormStart = iFormStart+iStart+2
'如果到文件尾了就退出
Loop Until (iFormStart+2) >= iFormEnd
RequestBinDate = ""
Set tStream = Nothing
End Sub
End Class

'----------------------------------------------------------------------------------------------------
'文件屬性類
Class FileInfo_Class
Dim FormName,FileName,FilePath,FileSize,FileType,FileStart,FileExt
'保存文件方法
Public Function SaveToFile (Path)
if lcase((right(Path,3))<>lcase(FileExt)) then '經典的上傳漏洞^_^
response.Write ("<script language=javascript>alert('警告:不允許上傳這種文件!');</script>")
response.end
end if
On Error Resume Next
Dim oFileStream
Set oFileStream = CreateObject ("ADODB.Stream")
oFileStream.Type = 1
oFileStream.Mode = 3
oFileStream.Open
oUpFileStream.Position = FileStart
oUpFileStream.CopyTo oFileStream,FileSize
oFileStream.SaveToFile Path,2
oFileStream.Close
Set oFileStream = Nothing
End Function

'取得文件數據
Public Function FileData
oUpFileStream.Position = FileStart
FileData = oUpFileStream.Read (FileSize)
End Function

End Class

'**************************************************
'函數名:IsObjInstalled
'作 用:檢查組件是否已經安裝
'參 數:strClassString ----組件名
'返回值:True ----已經安裝
' False ----沒有安裝
'**************************************************
Function IsObjInstalled(strClassString)
On Error Resume Next
IsObjInstalled = False
Err = 0
Dim xTestObj
Set xTestObj = Server.CreateObject(strClassString)
If 0 = Err Then IsObjInstalled = True
Set xTestObj = Nothing
Err = 0
End Function
'-------------根據指定名稱生成目錄---------
Function MakeNewsDir(foldername)
dim fso,f
Set fso = Server.CreateObject("Scripting.FileSystemObject")
Set f = fso.CreateFolder(foldername)
MakeNewsDir = True
Set fso = nothing
End Function

%>

Ⅱ asp上傳圖片並顯示的代碼

<html>
<head>
<meta http-equiv="陸中Content-Type" content="text/html; charset=utf-8">
<script language=javascript src="dialog.js"></script>
<script language="javascript">
document.write ("<link href='../language/zh-cn.css' type='text/css' rel='stylesheet'>");
document.write ("<link href='../dialog/dialog.css' type='text/css'毀孝 rel='stylesheet'>");
var sAction = "INSERT";
var sTitle = "上早余山傳圖片";
var oControl;
var oSeletion;
var sRangeType;
var sFromUrl = "http://";
var sAlt = "";
var sBorder = "0";
var sBorderColor = "";
var sFilter = "";
var sAlign = "";
var sWidth = "";
var sHeight = "";
var sVSpace = "";
var sHSpace = "";
var sSLTUrl = "";
var sCheckFlag = "file";
document.write("<title>上傳圖片</title>");
function InitDocument(){
d_fromurl.value = sFromUrl;
}
function RadioClick(what){
if (what=="url"){
d_checkfromfile.checked=false;
d_fromurl.disabled=false;
d_checkfromurl.checked=true;
d_file.myform.uploadfile.disabled=true;
}else{
d_checkfromurl.checked=false;
d_file.myform.uploadfile.disabled=false;
d_checkfromfile.checked=true;
d_fromurl.disabled=true;
}
}
function UploadLoaded(){
RadioClick(sCheckFlag);
}
function UploadError(sErrDesc){
AbleItems();
RadioClick('file');
divProcessing.style.display="none";
try {
BaseAlert(d_file.myform.uploadfile,eval(sErrDesc));
}
catch(e){}
}
function UploadSaved(sPathFileName, sPathFileName_s){
d_fromurl.value = sPathFileName;
sSLTUrl = sPathFileName_s;
ReturnValue();
}
function ReturnValue(){
sFromUrl = d_fromurl.value;
if (sFromUrl==""){
window.returnValue = null;}
else {
window.returnValue = sFromUrl;
}
window.close();
}
function ok(){
if (d_checkfromurl.checked){
ReturnValue();
}else{
if (!d_file.CheckUploadForm()) return false;
DisableItems();
divProcessing.style.display="";
d_file.myform.submit();
}
}
function DisableItems(){
d_checkfromfile.disabled=true;
d_checkfromurl.disabled=true;
d_fromurl.disabled=true;
Ok.disabled=true;
}
function AbleItems(){
d_checkfromfile.disabled=false;
d_checkfromurl.disabled=false;
d_fromurl.disabled=false;
Ok.disabled=false;
}
function doPreview(){
var url;
if (d_checkfromurl.checked){
url = d_fromurl.value;
}else{
url = d_file.document.myform.uploadfile.value;
}
if (url){
imgPreview.src = url;
setPreview()
}else{
tdPreview.innerHTML = "";
}
}
function setPreview(){
var width = imgPreview.width;
var height = imgPreview.height;
if (imgPreview.src){
var boxWidth = tdPreview.offsetWidth;
var boxHeight = tdPreview.offsetHeight;
if ((width>boxWidth)||(height>boxHeight)){
var nw = boxWidth/width;
var nh = boxHeight/height;
if (nw>nh){
height = boxHeight;
width = width*nh;
}else{
width = boxWidth;
height = height*nw;
}
}
tdPreview.innerHTML = "<img border=0 src='"+imgPreview.src+"' width='"+width+"' height='"+height+"'>";
tdPreviewSize.innerHTML = imgPreview.width+" * "+imgPreview.height;
}
}
</script>
<style type="text/css">
<!--
body {
margin-left: 3px;
margin-top: 3px;
margin-right: 3px;
margin-bottom: 3px;
}
-->
</style>
<body onLoad="InitDocument()">
<table width="100%" border=0 align=center cellpadding=0 cellspacing=5>
<tr>
<td><table border=0 cellpadding=0 cellspacing=0 align=center width="100%">
<tr>
<td><fieldset>
<legend><span lang=DlgImgSource>圖片來源</span></legend>
<table border=0 cellpadding=5 cellspacing=0 width="100%">
<tr>
<td><table border=0 cellpadding=0 cellspacing=2 width="100%">
<tr>
<td noWrap width="20%"><input type=radio id="d_checkfromfile" value="1" onClick="RadioClick('file')">
<label for=d_checkfromfile><span lang=DlgFromFile>上傳</span></label>
:</td>
<td noWrap width="80%"><Script Language=JavaScript>
document.write("<iframe id=d_file frameborder=0 src='asp/upload.asp?type=image&style=coolblue&language=zh-cn' width='100%' height='22' scrolling=no></iframe>");
</Script>
</td>
</tr>
<tr>
<td noWrap width="20%"><input type=radio id="d_checkfromurl" value="1" onClick="RadioClick('url')">
<label for=d_checkfromurl><span lang=DlgFromUrl>網路</span></label>
:</td>
<td noWrap width="80%"><input type=text id="d_fromurl" style="width:100%" size=30 value=""></td>
</tr>
</table></td>
</tr>
</table>
</fieldset></td>
</tr>
<tr>
<td height=5></td>
</tr>
<tr>
<td noWrap align=right colspan=2><input type=button id=btnPreivew lang=DlgImgPreview onClick="doPreview()" value="預覽">

<input type=submit value='確定' id=Ok onClick="ok()" lang=DlgBtnOK>

<input type=button value='取消' onClick="window.close();" lang=DlgBtnCancel></td>
</tr>
<tr>
<td><fieldset style="height:100%">
<legend><span lang=DlgImgPreview>預覽</span></legend>
<table border=0 cellpadding=0 cellspacing=5 width="100%" height="200" valign=top>
<tr>
<td bgcolor=#FFFFFF align=center valign=middle id=tdPreview height="100%"></td>
</tr>
<tr>
<td align=center id=tdPreviewSize></td>
</tr>
</table>
</fieldset></td>
</tr>
</table></td>
</tr>
</table>
<div id=divProcessing style="width:200px;height:30px;position:absolute;left:70px;top:100px;display:none">
<table border=0 cellpadding=0 cellspacing=1 bgcolor="#000000" width="100%" height="100%">
<tr>
<td bgcolor=#3A6EA5><marquee align="middle" behavior="alternate" scrollamount="5">
<font color=#FFFFFF><span lang=DlgComUploading></span></font>
</marquee></td>
</tr>
</table>
</div>
<img id=imgPreview src='' border=0 style="visibility:hidden" onload="setPreview()">
</body>
</html> 以上是其中的上傳圖片查看頁面 你去網路上找一下eWebEditor編輯器,這個就可以解決你想要的效果。如有不明白可以直接再問!

Ⅲ ASP上傳圖片並保存到access資料庫某個表中的源碼,能詳細解釋一下源碼的意思

給你個例子:
1、access表有以下幾個欄位:
id 自動編號,
filename 文本,
type 文本,
what OLE對象,
size 數字

2、上傳頁面(upfile.htm):
文件上傳<br />
<form action="upload.asp" method="post" enctype="multipart/form-data">
文件 <input type="file" name="file1" /> <input type="submit" value="上傳" />
</form>

3、提交頁面(upload.asp):
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!--#include file="UpLoad_Class.asp"-->
<%
dim upload
set upload = new AnUpLoad
upload.Exe = "*"
upload.MaxSize = 2 * 1024 * 1024 '2M
upload.charset = "utf-8"
upload.GetData()
if upload.ErrorID>0 then
response.Write upload.Description
else
dim file
for each frm in upload.forms("-1")
response.Write frm & "=" & upload.forms(frm) & "<br />"
next
set file = upload.files("file1")
if not(file is nothing) then
set conn = server.CreateObject("ADODB.connection")
conn.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ="&server.mappath("./")&"\db.mdb"
set rs = server.createobject("adodb.recordset")

rs.Open "pic", conn, 1, 3, 2
rs.addnew
rs.fields("filename") = file.LocalName
rs.fields("type") = file.ContentType
rs.fields("what") = file.GetBytes()
rs.fields("size") = file.Size
rs.update
Response.Redirect "listpic.asp"

end if
end if
set upload = nothing
%>

4、其中引用了UpLoad_Class.asp文件,是艾恩無組件上傳類,網上搜一下就能找到。

Ⅳ 求ASP圖片上傳源碼,具體要求如下

<%@ language="javascript"%>
<%
var self = Request.serverVariables("SCRIPT_NAME");
if (Request.serverVariables("REQUEST_METHOD")=="POST")
{
var oo = new uploadFile();
oo.path = "../../images/swf/"; //存放路徑,為空表示當前路徑,默認為uploadFile
oo.named = "date"; //命名方式,date表示用日期來命名,file表示用文件名本身,默認為file
oo.ext = "all"; //允許上傳的擴展名,all表示都允許,默認為態臘all
oo.over = true; //當存在相同文件名時是否覆蓋,默認為false
oo.size = 1*1024*1024; //最大位元組數限制,默認為1G
oo.upload();
Response.write('<script type="text/javascript">location.replace("'+self+'")<空櫻/script>');
}

//ASP無組件上傳類
function uploadFile()
{
var bLen = Request.totalBytes;
var bText = Request.binaryRead(bLen);
var oo = Server.createObject("ADODB.Stream");
oo.mode = 3;
this.path = "uploadFile";
this.named = "file";
this.ext = "all";
this.over = false;
this.size = 1*1024*1024*1024; //1GB

//文件上傳
this.upload = function ()
{
var o = this.getInfo();
if (o.size>this.size)
{
alert("文件過大,不能上傳!");
return;
}
var f = this.getFileName();
var ext = f.replace(/^.+\./,"");
if (this.ext!="all"&&!new RegExp(this.ext.replace(/,/g,"|"),"ig").test(ext))
{
alert("目前暫不支持擴展名為 "+ext+" 的文件上傳!");
return;
}
if (this.named=="date")
{
var f = new Date().toLocaleString().replace(/\D/g,"") + "." + ext;
}

oo.open();
oo.type = 1;
oo.write(o.bin);
this.path = this.path.replace(/[^\帆虧滑/\\]$/,"$&/");
var fso = Server.createObject("Scripting.FileSystemObject");
if(this.path!=""&&!fso.folderExists(Server.mapPath(this.path)))
{
fso.createFolder(Server.mapPath(this.path));
}
try
{
oo.saveToFile(Server.mapPath(this.path+f),this.over?2:1);

Response.write('<script type="text/javascript">parent.form.swf_Pic.value=("images/swf/'+f+'")</script>');

alert(f);
}
catch(e)
{

alert("對不起,此文件已存在!");
}
oo.close();
delete(oo);

}

//獲取二進制和文件位元組數
this.getInfo = function ()
{
oo.open();
oo.type=1;
oo.write(bText);
oo.position = 0;
oo.type=2;
oo.charset="unicode";
var gbCode=escape(oo.readText()).replace(/%u(..)(..)/g,"%$2%$1");
var sPos=gbCode.indexOf("%0D%0A%0D%0A")+12;
var sLength=bLen-(gbCode.substring(0,gbCode.indexOf("%0D%0A")).length/3)-sPos/3-6;
oo.close();

oo.open();
oo.type = 1;
oo.write(bText);
oo.position=sPos/3;
var bFile=oo.read(sLength);
oo.close();

return { bin:bFile, size:sLength };
}

//獲取文件名
this.getFileName = function ()
{
oo.open();
oo.type = 2;
oo.writeText(bText);
oo.position = 0;
oo.charset = "gb2312";
var fileName = oo.readText().match(/filename=\"(.+?)\"/i)[1].split("\\").slice(-1)[0];
oo.close();
return fileName;
}

function alert(msg)
{
Response.write('<script type="text/javascript">alert("'+msg+'");</script>');
}
}
%>
<body topmargin="0" marginwidth="0">

<form action="<%=self%>" method="POST" enctype="multipart/form-data" onSubmit="return (this.upFile.value!='');" name="myform" style="border: 1px solid #C0C0C0">
<input type="file" name="upFile" size="21"/>
<input type=submit name=submit value=上傳 class="tx1">
</form>

Ⅳ asp怎麼實現圖片文字圖片一起上傳源碼。求源碼

這個首先要查詢有圖片的新聞,讀取一條。然後取那條新聞以外的新聞。select top 1 * from tablename where img<>''

Ⅵ asp上傳圖片的代碼詳細的,最好是有步驟的

使用風聲無組件上傳類
<%
Set myRequest=new UpLoadClass
myRequest.FileType ="gif/jpg"'"gif/jpg"
myRequest.Savepath = "pic/"
myrequest.open

sql = "select * from tab"
set rs = server.createobject("adodb.recordset")
rs.open sql,conn,1,3
rs.addNew
rs("title") = myRequest.Form("title")
rs("file1") = myRequest.Form("file1")
rs("file2") = myRequest.Form("file2")
rs.update
set rs = nothing
%>
1.文件自動上傳到pic目錄自按日期時間生成不重復的文件名
2.上傳的文件的文件名自動生成並可這樣取慎飢出
myRequest.Form("file1")
3.text框的數據這樣取
myRequest.Form("title")
4.這個類的代碼可在這里
<%
'*****************************圖片上傳類開始*******************
Class UpLoadClass

Private p_MaxSize,p_FileType,p_SavePath,p_AutoSave,p_Error
Private objForm,binForm,binItem,strDate,lngTime
Public FormItem,FileItem

Public Property Get Version
Version="Rumor UpLoadClass Version 2.0"
End Property

Public Property Get Error
Error=p_Error
End Property

Public Property Get MaxSize
MaxSize=p_MaxSize
End Property
Public Property Let MaxSize(lngSize)
if isNumeric(lngSize) then
p_MaxSize=clng(lngSize)
end if
End Property

Public Property Get FileType
FileType=p_FileType
End Property
Public Property Let FileType(strType)
p_FileType=strType
End Property

Public Property Get SavePath
SavePath=p_SavePath
End Property
Public Property Let SavePath(strPath)
p_SavePath=replace(strPath,chr(0),"")
End Property

Public Property Get AutoSave
AutoSave=p_AutoSave
End Property
Public Property Let AutoSave(byVal Flag)
select case Flag
case 0:
case 1:
case 2:
case false:Flag=2
case else:Flag=0
end select
p_AutoSave=Flag
End Property

Private Sub Class_Initialize
p_Error = -1
p_MaxSize = 204800000000'0//設定上圓橡傳圖片大小
p_FileType = "jpg/gif"
p_SavePath = ""
p_AutoSave = 0
strDate = replace(cstr(Date()),"-","")
strDate = replace(cstr(Date()),"/","寬腔返")
lngTime = clng(timer()*1000)
Set binForm = Server.CreateObject("ADODB.Stream")
Set binItem = Server.CreateObject("ADODB.Stream")
Set objForm = Server.CreateObject("Scripting.Dictionary")
objForm.CompareMode = 1
End Sub

Private Sub Class_Terminate
objForm.RemoveAll
Set objForm = nothing
Set binItem = nothing
'binForm.Close()
Set binForm = nothing
End Sub

Public Sub Open()
if p_Error=-1 then
p_Error=0
else
Exit Sub
end if
Dim lngRequestSize,binRequestData,strFormItem,strFileItem
Const strSplit="'"">"
lngRequestSize=Request.TotalBytes
if lngRequestSize<1 then
p_Error=4
Exit Sub
end if
binRequestData=Request.BinaryRead(lngRequestSize)
binForm.Type = 1
binForm.Open
binForm.Write binRequestData

Dim bCrLf,strSeparator,intSeparator
bCrLf=ChrB(13)&ChrB(10)

intSeparator=InstrB(1,binRequestData,bCrLf)-1
strSeparator=LeftB(binRequestData,intSeparator)

Dim p_start,p_end,strItem,strInam,intTemp,strTemp
Dim strFtyp,strFnam,strFext,lngFsiz
p_start=intSeparator+2
Do
p_end =InStrB(p_start,binRequestData,bCrLf&bCrLf)+3
binItem.Type=1
binItem.Open
binForm.Position=p_start
binForm.CopyTo binItem,p_end-p_start
binItem.Position=0
binItem.Type=2
binItem.Charset="gb2312"
strItem=binItem.ReadText
binItem.Close()

p_start=p_end
p_end =InStrB(p_start,binRequestData,strSeparator)-1
binItem.Type=1
binItem.Open
binForm.Position=p_start
lngFsiz=p_end-p_start-2
binForm.CopyTo binItem,lngFsiz

intTemp=Instr(39,strItem,"""")
strInam=Mid(strItem,39,intTemp-39)

if Instr(intTemp,strItem,"filename=""")<>0 then
if not objForm.Exists(strInam&"_From") then
strFileItem=strFileItem&strSplit&strInam
if binItem.Size<>0 then
intTemp=intTemp+13
strFtyp=Mid(strItem,Instr(intTemp,strItem,"Content-Type: ")+14)
strTemp=Mid(strItem,intTemp,Instr(intTemp,strItem,"""")-intTemp)
intTemp=InstrRev(strTemp,"\")
strFnam=Mid(strTemp,intTemp+1)
objForm.Add strInam&"_Type",strFtyp
objForm.Add strInam&"_Name",strFnam
objForm.Add strInam&"_Path",Left(strTemp,intTemp)
objForm.Add strInam&"_Size",lngFsiz
if Instr(intTemp,strTemp,".")<>0 then
strFext=Mid(strTemp,InstrRev(strTemp,".")+1)
else
strFext=""
end if
if left(strFtyp,6)="image/" then
binItem.Position=0
binItem.Type=1
strTemp=binItem.read(10)
if strcomp(strTemp,chrb(255) & chrb(216) & chrb(255) & chrb(224) & chrb(0) & chrb(16) & chrb(74) & chrb(70) & chrb(73) & chrb(70),0)=0 then
if Lcase(strFext)<>"jpg" then strFext="jpg"
binItem.Position=3
do while not binItem.EOS
do
intTemp = ascb(binItem.Read(1))
loop while intTemp = 255 and not binItem.EOS
if intTemp < 192 or intTemp > 195 then
binItem.read(Bin2Val(binItem.Read(2))-2)
else
Exit do
end if
do
intTemp = ascb(binItem.Read(1))
loop while intTemp < 255 and not binItem.EOS
loop
binItem.Read(3)
objForm.Add strInam&"_Height",Bin2Val(binItem.Read(2))
objForm.Add strInam&"_Width",Bin2Val(binItem.Read(2))
elseif strcomp(leftB(strTemp,8),chrb(137) & chrb(80) & chrb(78) & chrb(71) & chrb(13) & chrb(10) & chrb(26) & chrb(10),0)=0 then
if Lcase(strFext)<>"png" then strFext="png"
binItem.Position=18
objForm.Add strInam&"_Width",Bin2Val(binItem.Read(2))
binItem.Read(2)
objForm.Add strInam&"_Height",Bin2Val(binItem.Read(2))
elseif strcomp(leftB(strTemp,6),chrb(71) & chrb(73) & chrb(70) & chrb(56) & chrb(57) & chrb(97),0)=0 or strcomp(leftB(strTemp,6),chrb(71) & chrb(73) & chrb(70) & chrb(56) & chrb(55) & chrb(97),0)=0 then
if Lcase(strFext)<>"gif" then strFext="gif"
binItem.Position=6
objForm.Add strInam&"_Width",BinVal2(binItem.Read(2))
objForm.Add strInam&"_Height",BinVal2(binItem.Read(2))
elseif strcomp(leftB(strTemp,2),chrb(66) & chrb(77),0)=0 then
if Lcase(strFext)<>"bmp" then strFext="bmp"
binItem.Position=18
objForm.Add strInam&"_Width",BinVal2(binItem.Read(4))
objForm.Add strInam&"_Height",BinVal2(binItem.Read(4))
end if
end if
objForm.Add strInam&"_Ext",strFext
objForm.Add strInam&"_From",p_start
intTemp=GetFerr(lngFsiz,strFext)
if p_AutoSave<>2 then
objForm.Add strInam&"_Err",intTemp
if intTemp=0 then
if p_AutoSave=0 then
strFnam=GetTimeStr()
if strFext<>"" then strFnam=strFnam&"."&strFext
end if
binItem.SaveToFile Server.MapPath(p_SavePath&strFnam),2
objForm.Add strInam,strFnam
end if
end if
else
objForm.Add strInam&"_Err",-1
end if
end if
else
binItem.Position=0
binItem.Type=2
binItem.Charset="gb2312"
strTemp=binItem.ReadText
if objForm.Exists(strInam) then
objForm(strInam) = objForm(strInam)&","&strTemp
else
strFormItem=strFormItem&strSplit&strInam
objForm.Add strInam,strTemp
end if
end if

binItem.Close()
p_start = p_end+intSeparator+2
loop Until p_start+3>lngRequestSize
FormItem=split(strFormItem,strSplit)
FileItem=split(strFileItem,strSplit)
End Sub

Private Function GetTimeStr()
lngTime=lngTime+1
GetTimeStr=strDate&lngTime
End Function

Private Function GetFerr(lngFsiz,strFext)
dim intFerr
intFerr=0
if lngFsiz>p_MaxSize and p_MaxSize>0 then
if p_Error=0 or p_Error=2 then p_Error=p_Error+1
intFerr=intFerr+1
end if
if Instr(1,LCase("/"&p_FileType&"/"),LCase("/"&strFext&"/"))=0 and p_FileType<>"" then
if p_Error<2 then p_Error=p_Error+2
intFerr=intFerr+2
end if
GetFerr=intFerr
End Function

Public Function Save(Item,strFnam)
Save=false
if objForm.Exists(Item&"_From") then
dim intFerr,strFext
strFext=objForm(Item&"_Ext")
intFerr=GetFerr(objForm(Item&"_Size"),strFext)
if objForm.Exists(Item&"_Err") then
if intFerr=0 then
objForm(Item&"_Err")=0
end if
else
objForm.Add Item&"_Err",intFerr
end if
if intFerr<>0 then Exit Function
if VarType(strFnam)=2 then
select case strFnam
case 0:strFnam=GetTimeStr()
if strFext<>"" then strFnam=strFnam&"."&strFext
case 1:strFnam=objForm(Item&"_Name")
end select
end if
binItem.Type = 1
binItem.Open
binForm.Position = objForm(Item&"_From")
binForm.CopyTo binItem,objForm(Item&"_Size")
binItem.SaveToFile Server.MapPath(p_SavePath&strFnam),2
binItem.Close()
if objForm.Exists(Item) then
objForm(Item)=strFnam
else
objForm.Add Item,strFnam
end if
Save=true
end if
End Function

Public Function GetData(Item)
GetData=""
if objForm.Exists(Item&"_From") then
if GetFerr(objForm(Item&"_Size"),objForm(Item&"_Ext"))<>0 then Exit Function
binForm.Position = objForm(Item&"_From")
GetData=binFormStream.Read(objForm(Item&"_Size"))
end if
End Function

Public Function Form(Item)
if objForm.Exists(Item) then
Form=objForm(Item)
else
Form=""
end if
End Function

Private Function BinVal2(bin)
dim lngValue,i
lngValue = 0
for i = lenb(bin) to 1 step -1
lngValue = lngValue *256 + ascb(midb(bin,i,1))
next
BinVal2=lngValue
End Function

Private Function Bin2Val(bin)
dim lngValue,i
lngValue = 0
for i = 1 to lenb(bin)
lngValue = lngValue *256 + ascb(midb(bin,i,1))
next
Bin2Val=lngValue
End Function

End Class

%>

Ⅶ asp上傳單個圖片的最簡單代碼是什麼

需要三個文件:
第一個(upload.asp)
<% Response.Buffer=True %>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">

<title>圖片上傳</title>
</head>
<body background="images/bg.gif" topmargin="30" style=""><div align="center">
<center>
<table border="1" cellspacing="1" style="border-collapse: collapse" bordercolor="#C0C0C0" width="420" id="AutoNumber69" bgcolor="#F5F5F5">
<tr>
<td width="100%" bgcolor="#F5F5F5" bordercolor="#F5F5F5"><form name="form1" method="post" action="uploadsave.asp" enctype="multipart/form-data">
<p align="center"><span style="font-size: 12px">圖片上傳:</span><br>
<br>

<input type="file" class="f11" name="file1" size="23">
<br>
<br>
<input type=submit name="submit" value="上 傳" class=anniu >
<br>
<br>
<span style="font-size: 12px">文件格式為<font color="#EC5106">*.gif,*.jpg,*.jpeg
</font></span></p>
</form></td>
</tr>
</table>
</center>
</body>
</html>
第二個文件(uploadsave.asp)
<% Response.Buffer=True %>

<html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>圖片上傳</title>

</head>

<body topmargin="20">
<!--#include FILE="upload_asjob.asp"-->
<%
set upload=new upload_5xsoft
set file=upload.file("file1")
if file.fileSize>0 then
'自動生成文件名
filename=date()
filename=filename&time()
filename=replace(filename,"-","")
filename=replace(filename,":","")
filename=replace(filename," ","")
filename=filename+"."
filenameend=file.filename
filenameend=split(filenameend,".")
if filenameend(1)="gif" or filenameend(1)="jpg" or filenameend(1)="jpeg" then
filename=filename&filenameend(1)
file.saveAs Server.mappath("uppic/"&filename)
response.write "<p align=center>"
response.write "圖片已成功上傳至伺服器中,請使用下面紅色地址添加圖片,<br><p align=center><a href=upload.asp>點擊這里重新上傳圖片!</a>"
response.write "</p>"
response.write "<p align=center>"
response.write "<font color=red>"
response.write "asjobcom/uppic/"&filename
response.write "</font></p>"
response.write "<p align=center>"
response.write "<a href='uppic/"&filename&"' target=_blank>點擊這里查看上傳的圖片</a>"
response.write "</p>"
response.write "<p align=center><a href=javascript:window.close()>【關閉窗口】</a>"
else
response.write "文件格式不對"
response.write "<a href=upload.asp>返回"
end if
set file=nothing
else
response.write "文件內容不能為空"
response.write "<a href=upload.asp>返回"
end if
set upload=nothing
response.write "<br>"
%>
最後一個(upload_asjob.asp)
<SCRIPT RUNAT=SERVER LANGUAGE=VBSCRIPT>

dim upfile_5xSoft_Stream

Class upload_5xSoft

dim Form,File,Version

Private Sub Class_Initialize
dim iStart,iFileNameStart,iFileNameEnd,iEnd,vbEnter,iFormStart,iFormEnd,theFile
dim strDiv,mFormName,mFormValue,mFileName,mFileSize,mFilePath,iDivLen,mStr
Version="化境編程界HTTP上傳程序 Version 1.0"
if Request.TotalBytes<1 then Exit Sub
set Form=CreateObject("Scripting.Dictionary")
set File=CreateObject("Scripting.Dictionary")
set upfile_5xSoft_Stream=CreateObject("Adodb.Stream")
upfile_5xSoft_Stream.mode=3
upfile_5xSoft_Stream.type=1
upfile_5xSoft_Stream.open
upfile_5xSoft_Stream.write Request.BinaryRead(Request.TotalBytes)

vbEnter=Chr(13)&Chr(10)
iDivLen=inString(1,vbEnter)+1
strDiv=subString(1,iDivLen)
iFormStart=iDivLen
iFormEnd=inString(iformStart,strDiv)-1
while iFormStart < iFormEnd
iStart=inString(iFormStart,"name=""")
iEnd=inString(iStart+6,"""")
mFormName=subString(iStart+6,iEnd-iStart-6)
iFileNameStart=inString(iEnd+1,"filename=""")
if iFileNameStart>0 and iFileNameStart<iFormEnd then
iFileNameEnd=inString(iFileNameStart+10,"""")
mFileName=subString(iFileNameStart+10,iFileNameEnd-iFileNameStart-10)
iStart=inString(iFileNameEnd+1,vbEnter&vbEnter)
iEnd=inString(iStart+4,vbEnter&strDiv)
if iEnd>iStart then
mFileSize=iEnd-iStart-4
else
mFileSize=0
end if
set theFile=new FileInfo
theFile.FileName=getFileName(mFileName)
theFile.FilePath=getFilePath(mFileName)
theFile.FileSize=mFileSize
theFile.FileStart=iStart+4
theFile.FormName=FormName
file.add mFormName,theFile
else
iStart=inString(iEnd+1,vbEnter&vbEnter)
iEnd=inString(iStart+4,vbEnter&strDiv)

if iEnd>iStart then
mFormValue=subString(iStart+4,iEnd-iStart-4)
else
mFormValue=""
end if
form.Add mFormName,mFormValue
end if

iFormStart=iformEnd+iDivLen
iFormEnd=inString(iformStart,strDiv)-1
wend
End Sub

Private Function subString(theStart,theLen)
dim i,c,stemp
upfile_5xSoft_Stream.Position=theStart-1
stemp=""
for i=1 to theLen
if upfile_5xSoft_Stream.EOS then Exit for
c=ascB(upfile_5xSoft_Stream.Read(1))
If c > 127 Then
if upfile_5xSoft_Stream.EOS then Exit for
stemp=stemp&Chr(AscW(ChrB(AscB(upfile_5xSoft_Stream.Read(1)))&ChrB(c)))
i=i+1
else
stemp=stemp&Chr(c)
End If
Next
subString=stemp
End function

Private Function inString(theStart,varStr)
dim i,j,bt,theLen,str
InString=0
Str=toByte(varStr)
theLen=LenB(Str)
for i=theStart to upfile_5xSoft_Stream.Size-theLen
if i>upfile_5xSoft_Stream.size then exit Function
upfile_5xSoft_Stream.Position=i-1
if AscB(upfile_5xSoft_Stream.Read(1))=AscB(midB(Str,1)) then
InString=i
for j=2 to theLen
if upfile_5xSoft_Stream.EOS then
inString=0
Exit for
end if
if AscB(upfile_5xSoft_Stream.Read(1))<>AscB(MidB(Str,j,1)) then
InString=0
Exit For
end if
next
if InString<>0 then Exit Function
end if
next
End Function

Private Sub Class_Terminate
form.RemoveAll
file.RemoveAll
set form=nothing
set file=nothing
upfile_5xSoft_Stream.close
set upfile_5xSoft_Stream=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 toByte(Str)
dim i,iCode,c,iLow,iHigh
toByte=""
For i=1 To Len(Str)
c=mid(Str,i,1)
iCode =Asc(c)
If iCode<0 Then iCode = iCode + 65535
If iCode>255 Then
iLow = Left(Hex(Asc(c)),2)
iHigh =Right(Hex(Asc(c)),2)
toByte = toByte & chrB("&H"&iLow) & chrB("&H"&iHigh)
Else
toByte = toByte & chrB(AscB(c))
End If
Next
End function
End Class

Class FileInfo
dim FormName,FileName,FilePath,FileSize,FileStart
Private Sub Class_Initialize
FileName = ""
FilePath = ""
FileSize = 0
FileStart= 0
FormName = ""
End Sub

Public function SaveAs(FullPath)
dim dr,ErrorChar,i
SaveAs=1
if trim(fullpath)="" or FileSize=0 or FileStart=0 or FileName="" then exit function
if FileStart=0 or right(fullpath,1)="/" then exit function
set dr=CreateObject("Adodb.Stream")
dr.Mode=3
dr.Type=1
dr.Open
upfile_5xSoft_Stream.position=FileStart-1
upfile_5xSoft_Stream.to dr,FileSize
dr.SaveToFile FullPath,2
dr.Close
set dr=nothing
SaveAs=0
end function
End Class
</SCRIPT>

Ⅷ 圖片上傳的ASP源代碼

4個文件實現無組件上傳4個文件實現無組件上傳
嵌套式調用:
<iframe name="ad" frameborder=0 width=100% height=50 scrolling=no src=uploada.asp></iframe>

直接鏈接:uploada.asp
文件保存路徑:upload
上傳文件類型和大小自己設置

===========================================
第一個文件:inc/confing.asp(inc為文件夾名稱)
<%
Const EnableUploadFile="Yes" '是否開放文件上傳
Const MaxFileSize=200 '上傳文件大小限制
Const UpFileType="gif|jpg|bmp|png|swf|doc|txt|rar|zip" '允許的上傳文件類型
%>

===========================================
第二個文件:inc/upload.asp

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.to oFileStream‚FileSize
oFileStream.SaveToFile FullPath‚2
oFileStream.Close
set oFileStream=nothing
SaveToFile=0
end function
End Class
%>

========================================
第三個文件:uploada.asp

<!--#include file="Inc/config.asp"-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css">
<!--
BODY{
BACKGROUND-COLOR: #f5feed;
font-size:9pt
}
.tx1 { height: 20px;font-size: 9pt; border: 1px solid; border-color: #000000; color: #0000FF}
-->
</style>
<link href="Manage/Inc/ManageMent.css" rel="stylesheet" type="text/css">
</head>
<body leftmargin="0" topmargin="0">
<%
if EnableUploadFile="Yes" then
%>
<form action="upfilea.asp" method="post" name="form1" enctype="multipart/form-data">
<input name="FileName" type="FILE" class="tx1" size="20">
<input type="submit" name="Submit" value="上傳" style="border:1px double rgb(88‚88‚88);font:9pt">
</form>
<%
end if
%>
</body>
</html>

============================
第四個文件:upfilea.asp

<!--#include file="Inc/config.asp"-->
<!--#include file="Inc/upload.asp"-->
<%
const upload_type=0 '上傳方法:0=無懼無組件上傳類,1=FSO上傳 2=lyfupload,3=aspupload,4=chinaaspupload

dim upload‚file‚formName‚SavePath‚filename‚fileExt
dim upNum
dim EnableUpload
dim Forumupload
dim ranNum
dim uploadfiletype
dim msg‚founderr
msg=""
founderr=false
EnableUpload=false
SavePath = "Upload" '存放上傳文件的目錄
if right(SavePath‚1)<>"/" then SavePath=SavePath&"/" '在目錄後加(/)
%>
<%
ComeinSTR=lcase(request.servervariables("HTTP_HOST"))
Url=split(ComeinSTR)
yourthing=Url(0)
%>
<html>
<head>
<link href="Manage/Inc/ManageMent.css" rel="stylesheet" type="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<%
if EnableUploadFile="NO" then
response.write "系統未開放文件上傳功能"
else

select case upload_type
case 0
call upload_0() '使用化境無組件上傳類
case else

end select

end if
%>
</body>
</html>
<%
sub upload_0() '使用化境無組件上傳類
set upload=new upload_file '建立上傳對象
for each formName in upload.file '列出所有上傳了的文件
set file=upload.file(formName) '生成一個文件對象
if file.filesize<100 then
msg="請先選擇你要上傳的文件!"
founderr=true
end if
if file.filesize>(MaxFileSize*1024) then
msg="文件大小超過了限制,最大隻能上傳" & CStr(MaxFileSize) & "K的文件!"
founderr=true
end if

fileExt=lcase(file.FileExt)
Forumupload=split(UpFileType‚"|")
for i=0 to ubound(Forumupload)
if fileEXT=trim(Forumupload(i)) then
EnableUpload=true
exit for
end if
next
if fileEXT="asp" or fileEXT="asa" or fileEXT="aspx" then
EnableUpload=false
end if
if EnableUpload=false then
'msg="這種文件類型不允許上傳!\n\n只允許上傳這幾種文件類型:" & UpFileType
response.write"<script language=javascript>alert('這種文件類型不允許上傳!\n\n只允許上傳這幾種文件類型:" &

UpFileType & "');"
response.write"javascript:history.go(-1)</script>"
founderr=true
end if

strJS="<script language=javascript>" & vbcrlf
if founderr<>true then
randomize
ranNum=int(900*rnd)+100
filename=SavePath&year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&ranNum&"."&fileExt

file.SaveToFile Server.mappath(FileName) '保存文件

msg="上傳文件成功!"

FileType=right(fileExt‚3)
select case FileType
case "jpg"‚"gif"‚"png"‚"bmp"
case "swf"
case else
strJS=strJS & "range.text=' 點擊瀏覽該文件';" & vbcrlf
end select
end if
strJS=strJS & "alert('" & msg & "');" & vbcrlf

strJS=strJS & "</script>"
response.write strJS
response.write "圖片上傳成功!文件路徑是 /" & filename & "<br>"
response.write "http://";; & yourthing & "/" & filename & "<br>"
set file=nothing
next
set upload=nothing
end sub
%>

Ⅸ asp文件上傳:文件上傳 源代碼

<! #include FILE="upload inc" >談如 <% dim upload file formName formPath iCount filename fileExt set upload=new upload_ xSoft 建立上傳對象 formPath="uploadimages/" 在目錄後啟戚加(/) if right(formPath )<>"/" then formPath=formPath&"/" iCount= for each formName in upload file 列出所有上傳了的文件 set file=upload file(formName) 生成一個文件對象 if file filesize< then response write "<font size= ><br>請先選擇你要上傳的圖片[ <a href=# onclick=history go( )>重新上傳</a> ]</font>" response end end if if file filesize> then 含旁啟 response write "<font size= ><br>圖片大小超過了限制[ <a href=# onclick=history go( )>重新上傳</a> ]</font>" response end end if

fileExt=lcase(right(file filename ))

if fileEXT<>" jpg" and fileEXT<>" gif" then response write "<font size= ><br>文件格式只能為jpg和gif格式[ <a href=# onclick=history go( )>重新上傳</a> ]</font>" response end end if randomize ranNum=int( *rnd)+ filename=formPath&year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&fileExt filename =year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&fileExt if file FileSize> then 如果 FileSize > 說明有文件數據 file SaveAs Server mappath(filename) 保存文件 response write "<script>parent form img value= "&FileName &" </script>"

iCount=iCount+ end if set file=nothing next set upload=nothing 刪除此對象

Response Write "<img src= "&" /UpLoad/UpLoadImages/"&FileName &" onload = DrawImage(this) >" response end %>

下面是upload inc的代碼

<SCRIPT RUNAT=SERVER LANGUAGE=VBSCRIPT> dim upfile_ xSoft_Stream Class upload_ xSoft dim Form File Version Private Sub Class_Initialize dim iStart iFileNameStart iFileNameEnd iEnd vbEnter iFormStart iFormEnd theFile dim strDiv mFormName mFormValue mFileName mFileSize mFilePath iDivLen mStr if Request TotalBytes< then Exit Sub set Form=CreateObject("Scripting Dictionary") set File=CreateObject("Scripting Dictionary") set upfile_ xSoft_Stream=CreateObject("Adodb Stream") upfile_ xSoft_Stream mode= upfile_ xSoft_Stream type= upfile_ xSoft_Stream open upfile_ xSoft_Stream write Request BinaryRead(Request TotalBytes) vbEnter=Chr( )&Chr( ) iDivLen=inString( vbEnter)+ strDiv=subString( iDivLen) iFormStart=iDivLen iFormEnd=inString(iformStart strDiv) while iFormStart < iFormEnd iStart=inString(iFormStart "name=""") iEnd=inString(iStart+ """") mFormName=subString(iStart+ iEnd iStart ) iFileNameStart=inString(iEnd+ "filename=""") if iFileNameStart> and iFileNameStart<iFormEnd then iFileNameEnd=inString(iFileNameStart+ """") mFileName=subString(iFileNameStart+ iFileNameEnd iFileNameStart ) iStart=inString(iFileNameEnd+ vbEnter&vbEnter) iEnd=inString(iStart+ vbEnter&strDiv) if iEnd>iStart then mFileSize=iEnd iStart else mFileSize= end if set theFile=new FileInfo theFile FileName=getFileName(mFileName) theFile FilePath=getFilePath(mFileName) theFile FileSize=mFileSize theFile FileStart=iStart+ theFile FormName=FormName file add mFormName theFile else iStart=inString(iEnd+ vbEnter&vbEnter) iEnd=inString(iStart+ vbEnter&strDiv)

if iEnd>iStart then mFormValue=subString(iStart+ iEnd iStart ) else mFormValue="" end if form Add mFormName mFormValue end if

iFormStart=iformEnd+iDivLen iFormEnd=inString(iformStart strDiv) wend End Sub

Private Function subString(theStart theLen) dim i c stemp upfile_ xSoft_Stream Position=theStart stemp="" for i= to theLen if upfile_ xSoft_Stream EOS then Exit for c=ascB(upfile_ xSoft_Stream Read( )) If c > Then if upfile_ xSoft_Stream EOS then Exit for stemp=stemp&Chr(AscW(ChrB(AscB(upfile_ xSoft_Stream Read( )))&ChrB(c))) i=i+ else stemp=stemp&Chr(c) End If Next subString=stemp End function

Private Function inString(theStart varStr) dim i j bt theLen str InString= Str=toByte(varStr) theLen=LenB(Str) for i=theStart to upfile_ xSoft_Stream Size theLen if i>upfile_ xSoft_Stream size then exit Function upfile_ xSoft_Stream Position=i if AscB(upfile_ xSoft_Stream Read( ))=AscB(midB(Str )) then InString=i for j= to theLen if upfile_ xSoft_Stream EOS then inString= Exit for end if if AscB(upfile_ xSoft_Stream Read( ))<>AscB(MidB(Str j )) then InString= Exit For end if next if InString<> then Exit Function end if next End Function

Private Sub Class_Terminate form RemoveAll file RemoveAll set form=nothing set file=nothing upfile_ xSoft_Stream close set upfile_ xSoft_Stream=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 "")+ ) Else GetFileName = "" End If End function

Private function toByte(Str) dim i iCode c iLow iHigh toByte="" For i= To Len(Str) c=mid(Str i ) iCode =Asc(c) If iCode< Then iCode = iCode + If iCode> Then iLow = Left(Hex(Asc(c)) ) iHigh =Right(Hex(Asc(c)) ) toByte = toByte & chrB("&H"&iLow) & chrB("&H"&iHigh) Else toByte = toByte & chrB(AscB(c)) End If Next End function End Class

lishixin/Article/program/net/201311/14198

Ⅹ 求ASP多張圖片上傳的詳細代碼

<%Server.ScriptTimeOut=5000%>
<!--#include file="conn.asp"-->
<!--#include file="upload_5xsoft.inc"-->
<html>
<head>
<title>文件上傳</title>
<link rel="stylesheet" href="images/style.css" type="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<%
dim upload,file,formName,formPath,iCount,exeec,wjm,lm
set upload=new upload_5xsoft

formPath="pictures/"
wjm=upload.form("file")
wjdx=0
for each formName in upload.objFile

if upload.form("zclj")="" then
set file=upload.file(formName)
wjdx = file.filesize
kzm = right(file.filename,4)
else
kzm = right(wjm,4)
end if

if lcase(kzm)<>".gif" and lcase(kzm)<>".bmp" and lcase(kzm)<>".jpg" then response.Redirect("add_pic.asp")

if upload.form("zclj")<>"" or wjdx<819200 then
set rs=server.CreateObject("adodb.recordset")
name=formPath + replace(cstr(date()),"-","") + replace(cstr(time()),":","") + kzm

'定義記錄集,把用戶輸入的數據插入到數據表中
sql="select * from message"
rs.open sql,conn,1,3
rs.addnew
rs("add_date")=right(cstr(date()),len(cstr(date()))-2)
rs("add_time")=time

if upload.form("zclj")="" then
rs("zp")=name
dx=cstr(file.filesize/1024)
if len(dx) >6 then dx=left(dx,6)
rs("wjdx") = dx +"K"
else
rs("zp")=wjm
rs("wjdx") = "0K"
end if

small_class_id=upload.form("small_class_id")
rs("small_class_id")=small_class_id
rs("big_class_id")=small_class_id

zt=upload.form("zt")
rs("zt")=zt

title=upload.form("title")
rs("title")=title

if wjdx>0 and wjdx<819200 and upload.form("zclj")="" then
file.SaveAs Server.mappath(name)
end if

iCount=iCount+1
rs.update
rs.close
cg="1"
end if
set file=nothing
next

set upload=nothing '刪除此對象
sub HtmEnd(Msg)
set upload=nothing
response.end
end sub
if cg="1" then response.redirect "add_pic.asp"
%>

不能上傳大於800K的文件(0.8M)!
</body>
</html>

=========

<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!--#include file="images/style.css" -->
<body>
<form name="dd" method="post" action="scfile.asp" enctype="multipart/form-data" >

<input type="hidden" name="act" value="upload">
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr><td>圖片主題:<input name="zt" type="text" class="inputtext" size="30" maxlength="100"></td></tr>
<tr><td>標題:<input name="title" type="text" class="inputtext" id="title" size="65"></td></tr>

<tr>
<td colspan="2" align="left" id="upid2">
<label>
<select name="small_class_id" id="small_class_id">
<option value="52">第1-8類商品</option>
<option value="44">第9-14類商品 </option>
<option value="79">第15-19類商品</option>
<option value="124">第20-22類商品</option>
</select>
</label> </td>
</tr>
<tr height="25">
<td colspan="2" align="left" id="upid"><input type="file" name="file1"></td>
</tr>

<tr height="25">
<td colspan="2" align="left" id="upid"></td>
</tr>

<tr height="25">
<td colspan="2" align="center">
<input type="submit" value=" 發 送 " name="cmdOk" class="inputbox" style="font-family: 宋體; font-size: 9pt;">

<input type="reset" name="Submit2" value=" 重 設 " class="inputbox" style="font-family: 宋體; font-size: 9pt;"> </td>
</tr>
</table>
</form>
</body>
</html>

熱點內容
遊程編碼c語言 發布:2025-05-16 21:26:51 瀏覽:586
帝來哪個配置值得購買 發布:2025-05-16 21:12:29 瀏覽:462
什麼是nodejs前端伺服器 發布:2025-05-16 21:12:17 瀏覽:405
編譯選項立即綁定未定義符號 發布:2025-05-16 20:55:13 瀏覽:906
linuxmysql慢日誌 發布:2025-05-16 20:47:58 瀏覽:271
村兩委有哪些配置 發布:2025-05-16 20:34:47 瀏覽:293
我的世界有什麼伺服器好玩的 發布:2025-05-16 20:28:57 瀏覽:484
c語言按位與運算 發布:2025-05-16 20:24:10 瀏覽:755
蘋果手機如何修改密碼安全 發布:2025-05-16 20:23:34 瀏覽:194
圖片文字識別演算法 發布:2025-05-16 20:21:54 瀏覽:47