A. 求一段ASP圖片上傳代碼。
Up.asp代碼:
<!--#include file="Upload.asp"-->
<%Server.ScriptTimeOut = 9999Dim PicSize, PicTypePicSize = 100 '圖片大小,單位KPicType = ".gif|.jpg|.bmp" '圖片格式%><HTML><HEAD><TITLE>圖片上傳</TITLE><META http-equiv="Content-Type" content="text/html; charset=gb2312"></HEAD><BODY><TABLE cellSpacing=0 cellPadding=0 width="100%" align=center border=0 class="tdbg"> <FORM method=post enctype=multipart/form-data action="?action=saveupload" style="margin:0px;"> <TR> <TD height="26"><INPUT type=file name=file size=40> *圖片大小不能超過<%=PicSize%>K <INPUT style=FONT-SIZE:9pt type="submit" value=" 上 傳 " name=Submit> </TR> </FORM></TABLE><%If Request("Action") = "saveupload" Then Call SaveUploadEnd If%></BODY></HTML><%Sub ShowErr(info) Response.Write "<SCRIPT language=javascript>alert("""&info&""");history.back();</SCRIPT>" Response.EndEnd SubSub SaveUpload() Dim AffixSize, AffixType Dim Affix, i Dim Upload, File, objFso Dim formName, FileName, FileType, FileSize, TotalBytes, ErrorType, FilePath, FullPath Dim Rs, Sql AffixSize = PicSize AffixType = PicType Set Upload = New Upload_Kings For Each formName In Upload.File Set File = Upload.File(formName) FileName = File.FileName FileType = LCase(Mid(FileName, InStrRev(FileName, "."))) FileName = Left(FileName, Len(FileName) - Len(FileType)) '獲取文件名(不含後綴),可以在這里定義文件名 FileSize = File.FileSize If InStr("|" & PicType & "|", "|" & FileType & "|") = 0 Then Call ShowErr("文件格式錯誤!") If FileSize < 1 Then Call ShowErr("請先選擇你要上傳的文件!") If FileSize>AffixSize*1024 Then Call ShowErr("文件大小不得超過 " & AffixSize & " K\n當前的文件大小為 " & Int(FileSize/1024) & " K") FilePath = "Images" FullPath = Server.Mappath(FilePath) Set objFso = Server.CreateObject("Scripting.FileSystemObject") If Not objFso.FolderExists(FullPath) Then objFso.CreateFolder (FullPath) Set objFso = Nothing File.SaveAs FullPath & "\" & FileName & FileType Set File = Nothing Next Set Upload = Nothing Response.Write "上傳成功!"End Sub%>Upload.asp代碼:
<%Dim Upfile_Kings_StreamClass Upload_Kings Dim Form, File Private Sub Class_Initialize() Dim iStart, iFileNameStart, iFileNameEnd, iEnd, vbEnter, iFormStart, iFormEnd, theFile Dim strDiv, mFormName, mFormValue, mFileName, mFileSize, mFilePath, iDivLen, mStr Set Form = CreateObject("Scripting.Dictionary") Set File = CreateObject("Scripting.Dictionary") Set Upfile_Kings_Stream = CreateObject("Adodb.Stream") Upfile_Kings_Stream.Mode = 3 Upfile_Kings_Stream.Type = 1 Upfile_Kings_Stream.Open Upfile_Kings_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.FileSize = mFileSize theFile.FileStart = iStart + 4 File.Add mFormName, theFile End If iFormStart = iFormEnd + iDivLen iFormEnd = inString(iFormStart, strDiv) - 1 Wend End Sub
Private Function subString(theStart, theLen) Dim i, c, stemp Upfile_Kings_Stream.Position = theStart - 1 stemp = "" For i = 1 To theLen If Upfile_Kings_Stream.EOS Then Exit For c = AscB(Upfile_Kings_Stream.Read(1)) If c > 127 Then If Upfile_Kings_Stream.EOS Then Exit For stemp=stemp&Chr(AscW(ChrB(AscB(Upfile_Kings_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_Kings_Stream.Size - theLen If i > Upfile_Kings_Stream.Size Then Exit Function Upfile_Kings_Stream.Position = i - 1 If AscB(Upfile_Kings_Stream.Read(1)) = AscB(MidB(Str, 1)) Then inString = i For j = 2 To theLen If Upfile_Kings_Stream.EOS Then inString = 0 Exit For End If If AscB(Upfile_Kings_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 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 FunctionEnd 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_Kings_Stream.Position = FileStart - 1 Upfile_Kings_Stream.Copyto dr, FileSize dr.SaveToFile FullPath, 2 dr.Close Set dr = Nothing SaveAs = 0 End FunctionEnd Class%>
B. asp上傳圖片源碼
<%
class clsUp '文件上傳類
'------------------------
Dim Form,File
Dim AllowExt_ '允許上傳類型(白名單)
Dim NoAllowExt_ '不允許上傳類型(黑名單)
Private oUpFileStream '上傳的數據流
Private isErr_ '錯誤的代碼,0或true表示無錯
Private ErrMessage_ '錯誤的字元串信息
Private isGetData_ '指示是否已執行過GETDATA過程
'------------------------------------------------------------------
'類的屬性
Public Property Get Version
Version="Version 2004"
End Property
Public Property Get isErr '錯誤的代碼,0或true表示無錯
isErr=isErr_
End Property
Public Property Get ErrMessage '錯誤的字元串信息
ErrMessage=ErrMessage_
End Property
Public Property Get AllowExt '允許上傳類型(白名單)
AllowExt=AllowExt_
End Property
Public Property Let AllowExt(Value) '允許上傳類型(白名單)
AllowExt_=LCase(Value)
End Property
Public Property Get NoAllowExt '不允許上傳類型(黑名單)
NoAllowExt=NoAllowExt_
End Property
Public Property Let NoAllowExt(Value) '不允許上傳類型(黑名單)
NoAllowExt_=LCase(Value)
End Property
'----------------------------------------------------------------
'類實現代碼
'初始化類
Private Sub Class_Initialize
isErr_ = 0
NoAllowExt="" '黑名單,可以在這里預設不可上傳的文件類型,以文件的後綴名來判斷,不分大小寫,每個每綴名用;號分開,如果黑名單為空,則判斷白名單
NoAllowExt=LCase(NoAllowExt)
AllowExt="" '白名單,可以在這里預設可上傳的文件類型,以文件的後綴名來判斷,不分大小寫,每個後綴名用;號分開
AllowExt=LCase(AllowExt)
isGetData_=false
End Sub
'類結束
Private Sub Class_Terminate
on error Resume Next
'清除變數及對像
Form.RemoveAll
Set Form = Nothing
File.RemoveAll
Set File = Nothing
oUpFileStream.Close
Set oUpFileStream = Nothing
End Sub
'分析上傳的數據
Public Sub GetData (MaxSize)
'定義變數
on error Resume Next
if isGetData_=false then
Dim RequestBinDate,sSpace,bCrLf,sInfo,iInfoStart,iInfoEnd,tStream,iStart,oFileInfo
Dim sFormValue,sFileName
Dim iFindStart,iFindEnd
Dim iFormStart,iFormEnd,sFormName
'代碼開始
If Request.TotalBytes < 1 Then '如果沒有數據上傳
isErr_ = 1
ErrMessage_="沒有數據上傳"
Exit Sub
End If
If MaxSize > 0 Then '如果限制大小
If Request.TotalBytes > MaxSize Then
isErr_ = 2 '如果上傳的數據超出限制大小
ErrMessage_="上傳的數據超出限制大小"
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 = Mid (sinfo,iFindStart,iFindEnd-iFindStart)
'如果是文件
If InStr (45,sInfo,"filename=""",1) > 0 Then
Set oFileInfo = new clsFileInfo
'取得文件屬性
iFindStart = InStr (iFindEnd,sInfo,"filename=""",1)+10
iFindEnd = InStr (iFindStart,sInfo,""""&vbCrLf,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.FileMIME = 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
isGetData_=true
end if
End Sub
'保存到文件,自動覆蓋已存在的同名文件
Public Function SaveToFile(Item,Path)
SaveToFile=SaveToFileEx(Item,Path,True)
End Function
'保存到文件,自動設置文件名
Public Function AutoSave(Item,Path)
AutoSave=SaveToFileEx(Item,Path,false)
End Function
'保存到文件,OVER為真時,自動覆蓋已存在的同名文件,否則自動把文件改名保存
Private Function SaveToFileEx(Item,Path,Over)
On Error Resume Next
Dim oFileStream
Dim tmpPath
Dim nohack '防黑緩沖
isErr=0
Set oFileStream = CreateObject ("ADODB.Stream")
oFileStream.Type = 1
oFileStream.Mode = 3
oFileStream.Open
oUpFileStream.Position = File(Item).FileStart
oUpFileStream.CopyTo oFileStream,File(Item).FileSize
nohack=split(path,".") '重要修改,防止黑客"\0"斷名偽裝!!!
tmpPath=nohack(0)&"."&nohack(ubound(nohack)) '重要修改,防止黑客"\0"斷名偽裝!!!
if Over then
if isAllowExt(GetFileExt(tmpPath)) then
oFileStream.SaveToFile tmpPath,2
Else
isErr_=3
ErrMessage_="該後綴名的文件不允許上傳!"
End if
Else
Path=GetFilePath(Path)
if isAllowExt(File(Item).FileExt) then
do
Err.Clear()
nohack=split(Path&GetNewFileName()&"."&File(Item).FileExt,".") '重要修改,防止黑客"\0"斷名偽裝!!!
tmpPath=nohack(0)&"."&nohack(ubound(nohack)) '重要修改,防止黑客"\0"斷名偽裝!!!
oFileStream.SaveToFile tmpPath
loop Until Err.number<1
oFileStream.SaveToFile Path
Else
isErr_=3
ErrMessage_="該後綴名的文件不允許上傳!"
End if
End if
oFileStream.Close
Set oFileStream = Nothing
if isErr_=3 then SaveToFileEx="" else SaveToFileEx=GetFileName(tmpPath)
End Function
'取得文件數據
Public Function FileData(Item)
isErr_=0
if isAllowExt(File(Item).FileExt) then
oUpFileStream.Position = File(Item).FileStart
FileData = oUpFileStream.Read (File(Item).FileSize)
Else
isErr_=3
ErrMessage_="該後綴名的文件不允許上傳!"
FileData=""
End if
End Function
'取得文件路徑
Public function GetFilePath(FullPath)
If FullPath <> "" Then
GetFilePath = Left(FullPath,InStrRev(FullPath, "\"))
Else
GetFilePath = ""
End If
End function
'取得文件名
Public Function GetFileName(FullPath)
If FullPath <> "" Then
GetFileName = mid(FullPath,InStrRev(FullPath, "\")+1)
Else
GetFileName = ""
End If
End function
'取得文件的後綴名
Public Function GetFileExt(FullPath)
If FullPath <> "" Then
GetFileExt = LCase(Mid(FullPath,InStrRev(FullPath, ".")+1))
Else
GetFileExt = ""
End If
End function
'取得一個不重復的序號
Public Function GetNewFileName()
dim ranNum
dim dtNow
dtNow=Now()
ranNum=int(90000*rnd)+10000
GetNewFileName=year(dtNow) & right("0" & month(dtNow),2) & right("0" & day(dtNow),2) & right("0" & hour(dtNow),2) & right("0" & minute(dtNow),2) & right("0" & second(dtNow),2) & ranNum
End Function
Public Function isAllowExt(Ext)
if NoAllowExt="" then
isAllowExt=cbool(InStr(1,";"&AllowExt&";",LCase(";"&Ext&";")))
else
isAllowExt=not CBool(InStr(1,";"&NoAllowExt&";",LCase(";"&Ext&";")))
end if
End Function
End Class
'----------------------------------------------------------------------------------------------------
'文件屬性類
Class clsFileInfo
Dim FormName,FileName,FilePath,FileSize,FileMIME,FileStart,FileExt
End Class
%>
C. php上傳圖片函數源碼(重金懸賞)
<?
//$_FILES['myFile']['tmp_name'] 儲存的臨時文件名,一般是系統默認
//is_uploaded_file()判斷上傳是否有內容
if(is_uploaded_file($_FILES['banner']['tmp_name'])){
//$_FILES["banner"]把上傳的內容存到一個數組中,並復制給$upfile
$upfile = $_FILES["banner"];
//可以通過print_r($upfile);查看數據的詳細內容
$name = $upfile["name"];
$type = $upfile["type"];
$size = $upfile["size"];
$tmp_name = $upfile["tmp_name"];
$error = $upfile["error"];
//switch循環用來為變數$ok賦值,如果圖片的格式$type(實際上就是文件的擴展名)滿足格式要求(循環里的case就是用來控制格式),那麼$ok = 1,以便下邊程序進行判斷
switch($type){
case 'image/pjpeg': $ok = 1 ;
break;
case 'image/jpeg': $ok = 1 ;
break;
case 'image/gif': $ok = 1 ;
break;
case 'image/png': $ok = 1 ;
break;
}
if($ok&&$error=='0'){
//move_uploaded_file(臨時文件,目標位置和文件名)
move_uploaded_file($tmp_name,'../up/'.$name);
echo "恭喜!上傳成功";
}
if(!$ok){
echo "抱歉!文件格式不正確";
}
}
?>
<form action="" method="post" name="upform" enctype="multipart/form-data">
上傳文件:
<input type="file" name="banner" size="60" class="t_input" />
<input type="submit" name="submit" value="上傳"/>
</form>
/*FORM標簽enctype屬性
表單中enctype="multipart/form-data"的意思,是設置表單的MIME編碼。默認情況,這個編碼格式是application/x-www-form-urlencoded,不能用於文件上傳;只有使用了multipart/form-data,才能完整的傳遞文件數據
*/
D. php簡單圖片上傳整站源碼有沒有
建議你從下面這個地方隨便找個圖片管理系統
www.kaiyuanba.cn/list/18-1.htm
E. 圖片上傳的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
%>
F. 請問,上傳圖片的源代碼怎麼寫還有,怎麼上傳本地圖片
文章里貼圖有兩種方法: 1,網路圖片鏈接:在文章編輯時,點擊上面功能區中的「插入圖片」在對話框中粘貼網路圖片地址,確定即可顯示。鉤選顯示源代碼即可看到「圖片的源代碼」。 2,本地上傳圖片:編輯文章時,點擊下面的「圖片剪貼板」—瀏覽—找到你計算機中准備好的圖片後,選中確定,然後隨游標插入圖片即可。需要注意的是本地上傳圖片要求一定是「jpg和gif格式的,容量不能超過200KB」。 上面的兩種方法都可以使用,而且鉤選顯示源代碼,都可以看到圖片添加的代碼,復制下來就可以了。
G. 圖片批量上傳代碼
用這個插件吧,jspsmartupload
upload.html頁面
<html>
<head>
<title>文件上傳</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<p></p>
<p align="center">上傳文件選擇</p>
<FORM METHOD="POST" ACTION="jsp/do_upload.jsp"
ENCTYPE="multipart/form-data">
<input type="hidden" name="TEST" value="good">
<table width="75%" border="1" align="center">
<tr>
<td><div align="center">1、
<input type="FILE" name="FILE1" size="30">
</div></td>
</tr>
<tr>
<td><div align="center">2、
<input type="FILE" name="FILE2" size="30">
</div></td>
</tr>
<tr>
<td><div align="center">3、
<input type="FILE" name="FILE3" size="30">
</div></td>
</tr>
<tr>
<td><div align="center">4、
<input type="FILE" name="FILE4" size="30">
</div></td>
</tr>
<tr>
<td><div align="center">
<input type="submit" name="Submit" value="上傳它!">
</div></td>
</tr>
</table>
</FORM>
</body>
</html>
do_upload.jsp頁面
<%@ page contentType="text/html; charset=gb2312" language="java"
import="java.util.*,com.jspsmart.upload.*" errorPage="" %>
<html>
<head>
<title>文件上傳處理頁面</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<%
// 新建一個SmartUpload對象
SmartUpload su = new SmartUpload();
// 上傳初始化
su.initialize(pageContext);
// 設定上傳限制
// 1.限制每個上傳文件的最大長度。
// su.setMaxFileSize(10000);
// 2.限制總上傳數據的長度。
// su.setTotalMaxFileSize(20000);
// 3.設定允許上傳的文件(通過擴展名限制),僅允許doc,txt文件。
// su.setAllowedFilesList("doc,txt");
// 4.設定禁止上傳的文件(通過擴展名限制),禁止上傳帶有exe,bat,
jsp,htm,html擴展名的文件和沒有擴展名的文件。
// su.setDeniedFilesList("exe,bat,jsp,htm,html,,");
// 上傳文件
su.upload();
// 將上傳文件全部保存到指定目錄
int count = su.save("/upload");
out.PRintln(count+"個文件上傳成功!<br>");
// 利用Request對象獲取參數之值
out.println("TEST="+su.getRequest().getParameter("TEST")
+"<BR><BR>");
// 逐一提取上傳文件信息,同時可保存文件。
for (int i=0;i<su.getFiles().getCount();i++)
{
com.jspsmart.upload.File file = su.getFiles().getFile(i);
// 若文件不存在則繼續
if (file.isMissing()) continue;
// 顯示當前文件信息
out.println("<TABLE BORDER=1>");
out.println("<TR><TD>表單項名(FieldName)</TD><TD>"
+ file.getFieldName() + "</TD></TR>");
out.println("<TR><TD>文件長度(Size)</TD><TD>" +
file.getSize() + "</TD></TR>");
out.println("<TR><TD>文件名(FileName)</TD><TD>"
+ file.getFileName() + "</TD></TR>");
out.println("<TR><TD>文件擴展名(FileExt)</TD><TD>"
+ file.getFileExt() + "</TD></TR>");
out.println("<TR><TD>文件全名(FilePathName)</TD><TD>"
+ file.getFilePathName() + "</TD></TR>");
out.println("</TABLE><BR>");
// 將文件另存
// file.saveAs("/upload/" + myFile.getFileName());
// 另存到以WEB應用程序的根目錄為文件根目錄的目錄下
// file.saveAs("/upload/" + myFile.getFileName(),
su.SAVE_VIRTUAL);
// 另存到操作系統的根目錄為文件根目錄的目錄下
// file.saveAs("c:\\temp\\" + myFile.getFileName(),
su.SAVE_PHYSICAL);
}
%>
</body>
</html>
參考資料來源:http://www.knowsky.com/3136.html
呵呵 正好前端時間我 也用到了
H. 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
%>
I. 求PHP圖片上傳源碼
是要圖片上傳功能源碼還是要網站樣式的?