Thu 28 Sep 2006 01:02:46
รบกวนพี่ๆทีมงานหน่อยนะครับ คือตอนนี้ผมจัดทำระบบให้สามารถทำการนำเอาโปรแกรมเล็กๆนามสกุล *.zip นะครับ ผมจะให้ทำการ upload มาเก็บไว้ระบบงานของผมแล้วก็จะให้ผู้อื่นสามารถทำการ download ไปใช้งานได้นะครับ รบกวนพี่ๆพอจามีตัวอย่างหรือแนวทางช่วยแนะนำผมหน่อยนะครับ
ขอบคุณมากครับ
http://forum.modoeye.com/module12-419.html#2365
Thu 28 Sep 2006 11:09:08
รบกวนอีกทีนะครับ คือผมได้โค้ดมาจากเว็บแห่งหนึ่งมีดังนี้นะครับ
---Upload.asp-----
<meta http-equiv="Content-Type" content="text/html; charset=windows-874">
<%
'***************************************
' File: Upload.asp
' Author: Jacob "Beezle" Gilley
' Email: avis7@airmail.net
' Date: 12/07/2000
' Comments: The code for the Upload, CByteString,
' CWideString subroutines was originally
' written by Philippe Collignon...or so
' he claims. Also, I am not responsible
' for any ill effects this script may
' cause and provide this script "AS IS".
' Enjoy!
'****************************************
Class FileUploader
Public Files
Private mcolFormElem
Private Sub Class_Initialize()
Set Files = Server.CreateObject("Scripting.Dictionary")
Set mcolFormElem = Server.CreateObject("Scripting.Dictionary")
End Sub
Private Sub Class_Terminate()
If IsObject(Files) Then
Files.RemoveAll()
Set Files = Nothing
End If
If IsObject(mcolFormElem) Then
mcolFormElem.RemoveAll()
Set mcolFormElem = Nothing
End If
End Sub
Public Property Get Form(sIndex)
Form = ""
If mcolFormElem.Exists(LCase(sIndex)) Then Form = mcolFormElem.Item(LCase(sIndex))
End Property
Public Default Sub Upload()
Dim biData, sInputName
Dim nPosBegin, nPosEnd, nPos, vDataBounds, nDataBoundPos
Dim nPosFile, nPosBound
biData = Request.BinaryRead(Request.TotalBytes)
nPosBegin = 1
nPosEnd = InstrB(nPosBegin, biData, CByteString(Chr(13)))
If (nPosEnd-nPosBegin) <= 0 Then Exit Sub
vDataBounds = MidB(biData, nPosBegin, nPosEnd-nPosBegin)
nDataBoundPos = InstrB(1, biData, vDataBounds)
Do Until nDataBoundPos = InstrB(biData, vDataBounds & CByteString("--"))
nPos = InstrB(nDataBoundPos, biData, CByteString("Content-Disposition"))
nPos = InstrB(nPos, biData, CByteString("name="))
nPosBegin = nPos + 6
nPosEnd = InstrB(nPosBegin, biData, CByteString(Chr(34)))
sInputName = CWideString(MidB(biData, nPosBegin, nPosEnd-nPosBegin))
nPosFile = InstrB(nDataBoundPos, biData, CByteString("filename="))
nPosBound = InstrB(nPosEnd, biData, vDataBounds)
If nPosFile <> 0 And nPosFile < nPosBound Then
Dim oUploadFile, sFileName
Set oUploadFile = New UploadedFile
nPosBegin = nPosFile + 10
nPosEnd = InstrB(nPosBegin, biData, CByteString(Chr(34)))
sFileName = CWideString(MidB(biData, nPosBegin, nPosEnd-nPosBegin))
oUploadFile.FileName = Right(sFileName, Len(sFileName)-InStrRev(sFileName, "\"))
nPos = InstrB(nPosEnd, biData, CByteString("Content-Type:"))
nPosBegin = nPos + 14
nPosEnd = InstrB(nPosBegin, biData, CByteString(Chr(13)))
oUploadFile.ContentType = CWideString(MidB(biData, nPosBegin, nPosEnd-nPosBegin))
nPosBegin = nPosEnd+4
nPosEnd = InstrB(nPosBegin, biData, vDataBounds) - 2
oUploadFile.FileData = MidB(biData, nPosBegin, nPosEnd-nPosBegin)
If oUploadFile.FileSize > 0 Then Files.Add LCase(sInputName), oUploadFile
Else
nPos = InstrB(nPos, biData, CByteString(Chr(13)))
nPosBegin = nPos + 4
nPosEnd = InstrB(nPosBegin, biData, vDataBounds) - 2
If Not mcolFormElem.Exists(LCase(sInputName)) Then mcolFormElem.Add LCase(sInputName), CWideString(MidB(biData, nPosBegin, nPosEnd-nPosBegin))
End If
nDataBoundPos = InstrB(nDataBoundPos + LenB(vDataBounds), biData, vDataBounds)
Loop
End Sub
'String to byte string conversion
Private Function CByteString(sString)
Dim nIndex
For nIndex = 1 to Len(sString)
CByteString = CByteString & ChrB(AscB(Mid(sString,nIndex,1)))
Next
End Function
'Byte string to string conversion
Private Function CWideString(bsString)
Dim nIndex
CWideString =""
For nIndex = 1 to LenB(bsString)
CWideString = CWideString & Chr(AscB(MidB(bsString,nIndex,1)))
Next
End Function
End Class
Class UploadedFile
Public ContentType
Public FileName
Public FileData
Public Property Get FileSize()
FileSize = LenB(FileData)
End Property
Public Sub SaveToDisk(sPath)
Dim oFS, oFile
Dim nIndex
If sPath = "" Or FileName = "" Then Exit Sub
If Mid(sPath, Len(sPath)) <> "\" Then sPath = sPath & "\"
Set oFS = Server.CreateObject("Scripting.FileSystemObject")
If Not oFS.FolderExists(sPath) Then Exit Sub
Set oFile = oFS.CreateTextFile(sPath & FileName, True)
For nIndex = 1 to LenB(FileData)
oFile.Write Chr(AscB(MidB(FileData,nIndex,1)))
Next
oFile.Close
End Sub
Public Sub SaveToDatabase(ByRef oField)
If LenB(FileData) = 0 Then Exit Sub
If IsObject(oField) Then
oField.AppendChunk FileData
End If
End Sub
End Class
%>
------------------------------
หน้า UploadXsample.asp-----------------
<%@ Language=VBScript %>
<%Option Explicit%>
<!-- #include file="upload.asp" -->
<%
'NOTE - YOU MUST HAVE VBSCRIPT v5.0 INSTALLED ON YOUR WEB SERVER
' FOR THIS LIBRARY TO FUNCTION CORRECTLY. YOU CAN OBTAIN IT
' FREE FROM MICROSOFT WHEN YOU INSTALL INTERNET EXPLORER 5.0
' OR LATER.
' Create the FileUploader
Dim Uploader, File
Set Uploader = New FileUploader
' This starts the upload process
Uploader.Upload()
'******************************************
' Use [FileUploader object].Form to access
' additional form variables submitted with
' the file upload(s). (used below)
'******************************************
Response.Write "<b>Thank you for your upload " & Uploader.Form("fullname") & "</b><br>"
' Check if any files were uploaded
If Uploader.Files.Count = 0 Then
Response.Write "File(s) not uploaded."
Else
' Loop through the uploaded files
For Each File In Uploader.Files.Items
' Check where the user wants to save the file
If Uploader.Form("saveto") = "disk" Then
' Save the file
File.SaveToDisk "\UploadFile\"
ElseIf Uploader.Form("saveto") = "database" Then
' Open the table you are saving the file to
Set RS = Server.CreateObject("ADODB.Recordset")
RS.Open "MyUploadTable", "CONNECT STRING OR ADO.Connection", 2, 2
RS.AddNew ' create a new record
RS("filename")=File.FileName
RS("filesize")=File.FileSize
RS("contenttype")=File.ContentType
' Save the file to the database
File.SaveToDatabase RS("filedata")
' Commit the changes and close
RS.Update
RS.Close
End If
' Output the file details to the browser
Response.Write "File Uploaded: " & File.FileName & "<br>"
Response.Write "Size: " & File.FileSize & " bytes<br>"
Response.Write "Type: " & File.ContentType & "<br><br>"
Next
End If
%>
--------------------------------------------
-ปัญหาของโค้ดที่ให้ดูคือ เมื่อทำการเลือกให้บันทึกไว้ใน disk จะไม่สามารถทำการบันทึกได้ผมต้องใส่ที่อยู่ให้ชัดเจนเช่น C:\Inetpub\www\UploadFile ถึงจะมาแต่ถ้าหากผมใส่ \UploadFile\ ก็จะไม่สามารถบันทึกได้
-ในส่วนของการเลือกให้บันทึกลงฐานข้อมูลเกิดการ Error ครับ ว่าดังนี้นะรับ
Error Type:
Microsoft VBScript runtime (0x800A01F4)
Variable is undefined: 'RS'
/TestUpload/uploadexmple.asp, line 42
ซึ่งผมได้ลองเช็ดดูแล้วก็ไม่น่าจะ Error นะครับ ไม่รู้พอจะแก้ยังงัย รบกวนพี่ๆทีมงานช่วยผมแก้หน่อยนะครับ ของคุณมากครับ
ส่วนการบันทึกลง DB นั้น ถ้าจะใช้ ADO Recordset นั้นถ้าผมจำไม่ผิดต้องทำการ select ข้อมูลออกมาเพื่อให้ได้โครงสร้าง table ก่อนนะครับ จากนั้นจึงสั่ง AddNew ได้ครับ
Thu 23 Aug 2007 09:04:47
<%
' Author Philippe Collignon
' Email PhCollignon@email.com
' Credit ãËéà¢Ò´éǹФÃѺ¡ÃسÒÍÂèÒàÍÒÍÍ¡
Response.Expires=0
Response.Buffer = TRUE
Response.Clear
byteCount = Request.TotalBytes
RequestBin = Request.BinaryRead(byteCount)
Dim UploadRequest
Set UploadRequest = CreateObject("Scripting.Dictionary")
BuildUploadRequest RequestBin
contentType = UploadRequest.Item("file").Item("ContentType")
filepathname = UploadRequest.Item("file").Item("FileName")
filename = Right(filepathname,Len(filepathname)-InstrRev(filepathname,"\"))
value = UploadRequest.Item("file").Item("Value")
detail = UploadRequest.Item("detail").Item("Value")
Set ScriptObject = Server.CreateObject("Scripting.FileSystemObject")
FilePath = Server.MapPath("picture") & "/" & filename
Set MyFile = ScriptObject.CreateTextFile(FilePath)
For i = 1 to LenB(value)
MyFile.Write chr(AscB(MidB(value,i,1)))
Next
MyFile.Close
%>
<font face='ms Sans serif' size=-1>
Upload ä»Âѧ path :<%=filePath%><br>
ª×èÍ file : </b><%=filename%><br>
¤Ó͸ԺÒ : <%=detail%>
------------------------------------
Error Type:
Microsoft VBScript runtime (0x800A0005)
Invalid procedure call or argument
/upload.asp, line 28
ทำไงครับ
Thu 23 Aug 2007 10:24:27
Sat 20 Oct 2007 09:24:54
คือผมมีปัญหาเรื่อง การ upload File ผมสามารถ upload File ได้นะคับแต่เป็น File ที่ไม่เกิน 2 MB ถ้ามากกว่ามันจะฟ้อง Err
RequestBin = Request.BinaryRead(byteCount)
น่าจะเป็นที่ขนาดไฟล์ แต่ผมก้กำหนดไว้เย่อะนะครับ
limitSize = 100000000000000 ช่วยตอบที
============= code =========================
<%@LANGUAGE="VBSCRIPT" CODEPAGE="874"%>
<!--#include virtual="/inc/conn.asp"-->
<!--#include virtual="/inc/upload.asp"-->
<meta http-equiv="Content-Type" content="text/html; charset=windows-874" />
<%
chk_date = Year(Date) & "-" & Month(Date) & "-" & Day(Date) & " " & Time
Folder_upload = Year(Date) & "-" & Month(Date) & "-" & Day(Date)
len1=Len(request("url"))-InstrRev(request("url"),"/") +1
pathinfo=Server.mappath(Request.ServerVariables("PATH_INFO"))
pathEnd = Len(pathinfo)-len1
filepath=left(pathinfo,pathEnd) & "\upload_file\"& Folder_upload
Response.Expires=0
Response.Buffer = True
byteCount = Request.TotalBytes
RequestBin = Request.BinaryRead(byteCount)
Dim UploadRequest
Set UploadRequest = CreateObject("Scripting.Dictionary")
BuildUploadRequest(RequestBin)
'response.Write BuildUploadRequest
'response.End()
FileSize = 0
limitSize = 100000000000000 ' 200 kByte
'limitSize = 8000 * 1024 ' 8 MByte
file_value = UploadRequest.Item("txtImages").Item("FileName")
if lenB(file_value) > limitSize then
response.write "<center><b>File ใหญ่เกิน " & FormatNumber(limitSize / 1024) & " KB </b></center><br>"
response.write "<center><input name='buttom_back' type='button' id='buttom_back' value=' < Back ' onclick='history.go(-1)'</center>"
response.end
end if
response.Write byteCount&"<br>"
response.write lenB(file_value)&">"
response.write limitSize
response.end()
if UploadRequest.Item("anote").Item("Value") = "" or session("username") = "" then
response.Redirect "attacking_upload.asp?Fid="& session("Fid")
else
anote = UploadRequest.Item("anote").Item("Value")
txtImages = UploadRequest.Item("txtImages").Item("FileName")
end if
If txtImages <> "" Then
filepath = Server.MapPath("upload_file")
Set fs = Server.CreateObject("Scripting.FileSystemObject")
If Not fs.FolderExists(filepath &"\"& Folder_upload) then
Set rf = fs.CreateFolder(filepath &"\"& Folder_upload)
Set rf = Nothing
End if
Set f = fs.GetFolder(filepath &"\"& Folder_upload)
Set f = Nothing
Set fs = Nothing
End if
'If Lcase(Right(txtImages,4)) = ".txt" Or Lcase(Right(txtImages,4)) = ".gif" Or Lcase(Right(txtImages,4)) = "jpeg" Then
'Upload File
filepath = filepath & "\" & Folder_upload & "\"
value = UploadRequest.Item("txtImages").Item("Value")
contentType = UploadRequest.Item("txtImages").Item("ContentType")
filename = UploadRequest.Item("txtImages").Item("FileName")
filename = Right(filename,Len(filename)-InstrRev(filename,"\"))
If LenB(value) > 0 Then
Set ScriptObject = Server.CreateObject("Scripting.FileSystemObject")
Set fileObj = ScriptObject.CreateTextFile(filepath & filename)
For i = 1 to LenB(value)
fileObj.Write chr(AscB(MidB(value,i,1)))
Next
fileObj.Close
Set fileObj = Nothing
Else
filename = 0
End if
Set rs = Server.CreateObject("ADODB.Recordset")
Sql = "SELECT * from Answer"
rs.Open Sql,conn,1,3
gdate=now()
CartID = 0
do while not rs.Eof
CartID = rs("F_ID")
session("CartID")=CartID
rs.movenext
loop
if rs.eof then
fileupload = Folder_upload&"/"&filename
Sql = "INSERT INTO Answer"
Sql = Sql & "(F_ID,A_Date,A_User,A_Detail,A_FileUpload) "
Sql = Sql & " VALUES "
Sql = Sql & "("&session("FID")&",'" &chk_date&"','"&session("username")&"','"&anote&"','"&fileupload&"')"
OpenDB()
conn.Execute(Sql)
Set Rs1 = Server.CreateObject("ADODB.Recordset")
sql1= "Update Forum set F_post=F_post+1 where F_ID="&session("FID")&""
rs1.Open sql1, conn, 1, 3
closeDb()
end if
response.Redirect "attacking_upload.asp?Fid="& session("Fid")
%>
Mon 22 Oct 2007 08:12:38
Wed 24 Oct 2007 16:28:37
Request object error 'ASP 0104 : 80004005'
Operation not Allowed
/sumipol/attacking_upload1.asp, line 17
========= line 17 คือ ===============
RequestBin = Request.BinaryRead(byteCount)
========== ขอบคุณครับ ====================
Wed 24 Oct 2007 20:25:26
Thu 25 Oct 2007 08:08:06
Thu 25 Oct 2007 11:21:47
Thu 25 Oct 2007 15:19:43
ผมลองแล้วมันฟ้องว่า ใช้ได้กับ IIS4,IIS5 ไม่แน่ใจว่า IIS6 ต้องลองแก้ที่ AspMaxRequestEntityAllowed ของไฟล์ metabase.XML หรือเปล่าครับ
Fri 26 Oct 2007 12:44:32
Mon 29 Oct 2007 11:14:34
มีวิธีแก้ os vista languages Japanese ให้เป็น vista languages English หรือเปล่าคับ
ขอบคุณครับ
Tue 30 Oct 2007 11:07:34
Tue 6 Nov 2007 10:43:36
Wed 7 Nov 2007 05:10:03
http://support.modoeye.com/Knowledge_bases/Website_hosting/Uploading/Using_cuteFTP.html
Wed 19 Mar 2008 17:46:07
ใช้ asp และใช้ access 2000 เป็นฐานข้อมูล แต่ไม่สามารถบันทึกลงฐานข้อมูลได้ ทำไงดี และดูแล้วโค้ดก็ไม่น่าจะผิด มันน่าจะเกิดจากอะไร
อยากให้ช่วยหาสาเหตุอื่นๆให้หน่อย
Wed 19 Mar 2008 23:32:13

















