 |
|
|
 |
 |
|
///นี่คือส่วนของfile upload
<%
Sub BuildUploadRequest(RequestBin)
PosBeg = 1
PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(13)))
boundary = MidB(RequestBin,PosBeg,PosEnd-PosBeg)
boundaryPos = InstrB(1,RequestBin,boundary)
Do until (boundaryPos=InstrB(RequestBin,boundary & getByteString("--")))
Dim UploadControl
Set UploadControl = CreateObject("Scripting.Dictionary")
Pos = InstrB(BoundaryPos,RequestBin,getByteString("Content-Disposition"))
Pos = InstrB(Pos,RequestBin,getByteString("name="))
PosBeg = Pos+6
PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(34)))
Name = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
PosFile = InstrB(BoundaryPos,RequestBin,getByteString("filename="))
PosBound = InstrB(PosEnd,RequestBin,boundary)
If PosFile<>0 AND (PosFile<PosBound) Then
PosBeg = PosFile + 10
PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(34)))
FileName = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
UploadControl.Add "FileName", FileName
Pos = InstrB(PosEnd,RequestBin,getByteString("Content-Type:"))
PosBeg = Pos+14
PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(13)))
ContentType = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
'UploadControl.Add "ContentType",ContentType
PosBeg = PosEnd+4
PosEnd = InstrB(PosBeg,RequestBin,boundary)-2
Value = MidB(RequestBin,PosBeg,PosEnd-PosBeg)
Else
Pos = InstrB(Pos,RequestBin,getByteString(chr(13)))
PosBeg = Pos+4
PosEnd = InstrB(PosBeg,RequestBin,boundary)-2
Value = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
End If
UploadControl.Add "Value" , Value
UploadRequest.Add name, UploadControl
BoundaryPos=InstrB(BoundaryPos+LenB(boundary),RequestBin,boundary)
Loop
End Sub
Function getByteString(StringStr)
For i = 1 to Len(StringStr)
char = Mid(StringStr,i,1)
getByteString = getByteString & chrB(AscB(char))
Next
End Function
Function getString(StringBin)
getString =""
For intCount = 1 to LenB(StringBin)
getString = getString & chr(AscB(MidB(StringBin,intCount,1)))
Next
End Function
%>
|
 |
 |
 |
 |
Date :
30 มิ.ย. 2548 08:39:05 |
By :
tong |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
<!--#include file="ConnectBase.inc"-->
<!--#include file="uploadx.asp"-->//เป็นการเรียกไฟล์อัพโหลดเข้ามา
<%session.LCID=1033%>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874">
</head>
<body>
<%
'********************************************************************************************************************************************
len1=Len(request("url"))-InstrRev(request("url"),"/")
pathinfo=Server.mappath(Request.ServerVariables("PATH_INFO"))
pathEnd = Len(pathinfo)-len1
filepath=left(pathinfo,pathEnd) '& "db\"
Response.Expires=0
Response.Buffer = TRUE
Response.Clear
byteCount = Request.TotalBytes
RequestBin = Request.BinaryRead(byteCount)
Dim UploadRequest
Set UploadRequest = CreateObject("Scripting.Dictionary")
BuildUploadRequest RequestBin
filepathname = UploadRequest.Item("pics").Item("FileName") //รับไฟล์ภาพมาจากฟอร์ม*********
filename = Right(filepathname,Len(filepathname)-InstrRev(filepathname,"\"))
'*********************************************************************************************************************************************
'***********************สร้างรหัสในการเก็บรูป******************************
mdate=replace(date(),"/","")
mtime=replace(time(),":","")
ntime=left(mtime,5)
newname=mdate+ntime
filename=newname&filename
'********************รับค่าจากการ post***********************************
dates=date
headnews = UploadRequest.Item("headnews").Item("Value") //รับข้อมูลมาจากฟอร์ม******
detail_news=UploadRequest.Item("detail_news").Item("Value")//รับข้อมูลมาจากฟอร์ม******
value = UploadRequest.Item("pics").Item("Value")
limitSize = 115 * 70
if lenB(value) > limitSize then
response.write "<b><center>File ใหญ่เกิน " & _
formatNumber(limitSize / 1024) & _
" kB คลิก Back กลับไปเลือกใหม่"
response.end
end if
if lenB(value)<>0 then
Sql="INSERT INTO news(dates,headnews,detail_news,news_pics) Values ('"& dates &"','"& headnews &"','"& detail_news &"','"& filename &"')"
conn.begintrans
conn.execute SQL
conn.committrans
'-------------------- upload picture to server ------------------------
Set ScriptObject = Server.CreateObject("Scripting.FileSystemObject")
Set fileObj = ScriptObject.CreateTextFile(filepath&"..\news\"& filename)
For i = 1 to LenB(value)
fileObj.Write chr(AscB(MidB(value,i,1)))
Next
fileObj.Close
else
Sql="INSERT INTO news(dates,headnews,detail_news) Values ('"& dates &"','"& headnews &"','"& detail_news &"')"
conn.begintrans
conn.execute SQL
conn.committrans
end if
%>
<br><br><center><font color = '#000000' face = 'ms sans serif' size = 2><b> เพิ่มข่าวใหม่เรียบร้อยแล้วครับ</b></font></center>
<META HTTP-EQUIV="REFRESH" CONTENT="3; URL= adminnews.asp">
</body>
</html>
|
 |
 |
 |
 |
Date :
30 มิ.ย. 2548 08:42:29 |
By :
tong |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อธิบายเพิ่มเติม
'-------------------- upload picture to server ------------------------
Set ScriptObject = Server.CreateObject("Scripting.FileSystemObject")
Set fileObj = ScriptObject.CreateTextFile(filepath&"..\news\"& filename) //จะเห็น\news\นี่คือโฟลเดอร์newsที่เก็บภาพข่าวนะครับ
For i = 1 to LenB(value)
fileObj.Write chr(AscB(MidB(value,i,1)))
Next
fileObj.Close
|
 |
 |
 |
 |
Date :
30 มิ.ย. 2548 08:45:35 |
By :
tong |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|