 |
|
|
 |
 |
|
พี่บอกได้ถูกแต่ผมยังทำไม่ได้เลยครับ ต้องขออภัยจริงๆ รบกวนอีกครั้งนะ
ไม่ทราบว่าจะบันทึกยังไงถึงจะลงฐานข้อมูลได้ครับ
ชื่อไฟล์ data ชื่อตาราง file ชื่อ ฟิล xx
พี่ช่วยกรุณาเขียนให้เต็มสักนิดนึงนะครับ ผมไม่รู้จริงๆ
------------------------------------------------------------------------------
ตัวอืนผมทำได้ตามตัวอย่างในบทเรียนของพี่ แต่ตัวนี้หล่ะยากจริงๆ
------------------------------------------------------------------------------
Set fs=Server.CreateObject("Scripting.FileSystemObject")
Set uploadfile=fs.CreateTextFile(Server.Mappath("Picture"&"/"&filename_new))
uploadfile.Write uploaddata.Item("file").Item("value")
-------------------------------------------------------------------------------
ผมแทรกตรงนี้แล้วไม่ได้และมองไม่เห็นไฟล์
-------------------------------------------------------------------------------
Set Conn=Server.Createobject("ADODB.Connection")
Conn.Open "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath("picture/data.mdb"),"" , ""
Set RS =Server.CreateObject("ADODB.Recordset")
RS.open Sql,Conn,1,3
rs.AddNew
rs("xx") = filename_new
rs.Update
-------------------------------------------------------------------------------
Response.write(" ได้")
uploadfile.Close
set fs=Nothing
-------------------------------------------------------------------------------
uploadfile.Close
set fs=Nothing

|
 |
 |
 |
 |
Date :
14 ต.ค. 2547 15:53:51 |
By :
chaivat |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลืมครับ
sql ="Select * From file"
|
 |
 |
 |
 |
Date :
14 ต.ค. 2547 16:54:21 |
By :
chaivat |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมใช้แบบนี้นะ อาจไม่เหมือนบทเรียนนะ ตรงที่สำคัญผมจะใส่เป็นสีน้ำเงินนะครับ
สร้าง test.html
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874">
</head>
<body>
<form action="process.asp" method="post" enctype="multipart/form-data" name="form1">
<input name="upload" type="file" id="upload" value="">
<input type="submit" name="Submit" value="Submit">
</form>
</body>
</html>
สร้าง Upload.asp
<%
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
%>
จากนั้นก็สร้าง process.asp
<%
'กำหนดที่เก็บ File
filepath=Server.MapPath("/สถานที่เก็บ")
'กำหนด script time out เพื่อให้สามารถ upload ข้อมูลได้นานขึ้น ถ้ามีข้อมูลขนาดใหญ่ xxx คือระยะเวลาที่ต้องการ
server.scripttimeout = xxxx
%>
<!--#include file=upload.asp-->
<%
'--------------------------------------------------------------
' 2.รับค่าจากฟอร์มในหน้าที่แล้ว
byteCount = Request.TotalBytes
RequestBin = Request.BinaryRead(byteCount)
'--------------------------------------------------------------
' 3.ประกาศตัวแปรและเรียกใช้ Dictionary component
Dim UploadRequest
Set UploadRequest = CreateObject("Scripting.Dictionary")
BuildUploadRequest RequestBin
'------------------------------------------------------------------
' 4.รับค่าฟิลด์ประเภท blob
' 4.1. รับค่าของข้อมูลที่ต้องการ upload
filepathname = UploadRequest.Item("upload").Item("FileName")
pimages = Right(filepathname,Len(filepathname)-InstrRev(filepathname,"\"))
psvalue = UploadRequest.Item("upload").Item("Value")
'------------------------------------------------------------------
' 5.สร้าง sub program สำหรับทำขั้นตอนต่อไปนี้
' 5.1.validate ค่าฟิลด์ประเภท blob
' 5.2.จำกัดขนาดของไฟล์ฟิลด์ประเภท blob
' 5.3.upload to server
Sub uploadimage(imgvalue,imgname)
' 5.1.validate ค่าฟิลด์ประเภท blob
if filepathname <> "" then
if lenB(imgvalue) = 0 then
response.write "<b>Can't not Upload " & "ไม่มีไฟล์นี้ / ไฟล์มีขนาดเป็นศูนย์ คลิก Back </b>"
response.end
end if
end if
' 5.2.จำกัดขนาดของไฟล์ฟิลด์ประเภท blob
limitSize = 300 * 1024 ' 300 kByte
if lenB(imgvalue) > limitSize then
response.write "<b>File ใหญ่เกิน " & FormatNumber(limitSize / 1024) & "300 KB คลิก Back กลับไปเลือกใหม่"
response.end
end if
' ตรวจสอบว่ามี File นั้นอยู่บน Server หรือไม่ ถ้ามีก็ทำการเปลี่ยนชื่อ File ให้
i=1
while reportfilestatus(filepath&"\"&imgname) <> "false"
if reportfilestatus(filepath&"\"&imgname) = "true" then
imgname = left(imgname,4)&i&right(imgname,len(left(imgname,4)))
pimages = imgname
i=i+1
end if
wend
' 5.3.upload to server
if filepathname <> "" then
Set ScriptObject = Server.CreateObject("Scripting.FileSystemObject")
Set fileObj = ScriptObject.CreateTextFile(filepath & "/" & imgname)
For i = 1 to LenB(imgvalue)
fileObj.Write chr(AscB(MidB(imgvalue,i,1)))
Next
fileObj.Close
end if
End Sub
'-------------------------------------------------------------------
' 6.เรียกใช้ uploadimage()
Call uploadimage(psvalue,pimages)
function reportfilestatus(filespec)
set fso =createobject("scripting.filesystemobject")
if (fso.fileexists(filespec)) then
msg = "true"
else
msg = "false"
end if
reportfilestatus = msg
end function
' เพิ่มข้อมูลลง DataBase
sql = "select * from ชื่อตาราง"
set rs=server.createobject("adodb.recordset")
rs.open sql,conn,1,3
rs.addnew
rs("ชื่อฟิล")= pimages
rs.update
rs.close
conn.close
%>
ตอนนี้ผมใช้อยู่ประมาณนี้นะครับ พอดีไปเจอจากเว็บไหนจำไม่ได้แล้ว แต่ก็ประมาณนี้หละครับ ลองเอาไปแก้ดู
|
 |
 |
 |
 |
Date :
15 ต.ค. 2547 09:44:34 |
By :
tuntigon |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แก้ไขข้างบนนิดหน่อยครับ ตรงนี้ผมลืม
' เพิ่มข้อมูลลง DataBase
Set Conn=Server.Createobject("ADODB.Connection")
Conn.Open "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath("ฐานข้อมูล"),"" , ""
sql = "select * from ชื่อตาราง"
set rs=server.createobject("adodb.recordset")
rs.open sql,conn,1,3
rs.addnew
rs("ชื่อฟิล")= pimages
rs.update
rs.close
conn.close
|
 |
 |
 |
 |
Date :
15 ต.ค. 2547 14:11:17 |
By :
tuntigon |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอขอบคุณมากๆ จริงๆ ครับสำหรับข้อมูล code ที่เขียนให้ ขอให้เป็นคนดีคนเก่งของสังคมอย่างนี้ตลอดไปนะครับ ขอบคุณครับ
|
 |
 |
 |
 |
Date :
19 ต.ค. 2547 10:09:45 |
By :
chaivat |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
งงงงงงงงงงงงงงงงงงงงงงงงงงงงงงงง
|
 |
 |
 |
 |
Date :
9 พ.ย. 2547 19:56:29 |
By :
ต้น |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลอกโค้ดจากความคิดที่ 5 ไปใช้ ทำไม รันไม่ผ่านเลย ขึ้นเป็น
Invalid procedure call or argument
/daode2-12-50/member/process.asp, line 62
|
 |
 |
 |
 |
Date :
3 ธ.ค. 2550 02:12:33 |
By :
SkyWalker |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|