 |
|
รับค่า Textbox <b>Uploads.asp </b> <% Function TextToBinary TextToBinary & ChrB(Asc(character)) |
|
 |
|
|
 |
 |
|
Uploads.asp
<%
Function TextToBinary(text)
For i=1 to Len(text)
character=Mid(text,i,1)
TextToBinary=TextToBinary & ChrB(Asc(character))
Next
End Function
Function BinaryToText(Binary)
BinaryToText=""
For i=1 to LenB(Binary)
character=MidB(Binary,i,1)
BinaryToText=BinaryToText & Chr(AscB(character))
Next
End Function
Set uploaddata=CreateObject("Scripting.Dictionary")
data=Request.BinaryRead(Request.TotalBytes)
posend=InStrB(1,data,TextToBinary(Chr(13)))
header=MidB(data,1,posend-1)
endheader=header&TextToBinary("_")
pos_header=1
pos_endheader=InStrB(1,data,endheader)
Do While pos_header<>pos_endheader
Set sub_uploaddata=CreateObject("Scripting.Dictionary")
pos_name=InStrB(pos_header,data,TextToBinary("name="))
pos_namebegin=pos_name+6
pos_nameend=InStrB(pos_namebegin,data,TextToBinary(Chr(34)))
name=BinaryToText(MidB(data,pos_namebegin,pos_nameend-pos_namebegin))
pos_file=InStrB(pos_nameend,data,TextToBinary("filename="))
enddata=InStrB(pos_nameend,data,header)
If (pos_file<>0)And(pos_file<enddata) Then
pos_filebegin=pos_file+10
pos_fileend=InStrB(pos_filebegin,data,TextToBinary(Chr(34)))
filename=BinaryToText(MidB(data,pos_filebegin,pos_fileend-pos_filebegin))
sub_uploaddata.Add "filename",filename
pos_content=InStrB(pos_fileend,data,TextToBinary("Content-Type:"))
pos_contentbegin=pos_content+14
pos_contentend=InStrB(pos_contentbegin,data,TextToBinary(Chr(13)))
contenttype=BinaryToText(MidB(data,pos_contentbegin,pos_contentend-pos_contentbegin))
sub_uploaddata.Add "contenttype",contenttype
pos_valuebegin=pos_contentend+4
pos_valueend=InStrB(pos_valuebegin,data,header)-2
Value=BinaryToText(MidB(data,pos_valuebegin,pos_valueend-pos_valuebegin))
sub_uploaddata.Add "value",value
Else
pos_valuebegin=pos_nameend+4
pos_valueend=InStrB(pos_valuebegin,data,header)-2
Value=BinaryToText(MidB(data,pos_valuebegin,pos_valueend-pos_valuebegin))
sub_uploaddata.Add "value",value
End If
uploaddata.Add name,sub_uploaddata
pos_header=InStrB(pos_header+LenB(header),data,header)
Loop
%>
Sample1.asp
<html>
<body bgcolor="#FFFFFF">
<form name="form1" method="post" action="Sample2.asp" enctype="multipart/form-data">
Name : <input type="text" name="name"><br>
<input type="file" name="file">
<input type="submit" name="Submit" value="Uploads">
</form>
</body>
</html>
Sample2.asp
<html>
<body bgcolor="#FFFFFF">
<%
bytecount=Request.TotalBytes
If bytecount<80000 Then ' กำหนดขนาดไฟล์ไม่เกิน 80 K
%>
<!--#Include File="uploads.asp"-->
<%
filename=uploaddata.Item("file").Item("filename")
pos_filebegin=InStrRev(filename,"\")
pos_fileend=Len(filename)
filename_new=Mid(filename,pos_filebegin+1,pos_fileend-pos_filebegin)
' กำหนด ประเภทของไฟล์ที่จะ สามารถ uploads ได้
If Instr(filename_new,".jpg")<>0 Or Instr(filename_new,".gif")<>0 Or Instr(filename_new,".jpeg")<>0 Then
Set fs=Server.CreateObject("Scripting.FileSystemObject")
Set uploadfile=fs.CreateTextFile(Server.Mappath("picture"&"/"&filename_new))
uploadfile.Write uploaddata.Item("file").Item("value")
Response.write(" Uploads ไฟล์สำเร็จ ")
Response.write("<br> ไฟล์ชื่อ " &filename_new)
' หากต้องการ นำชื่อไฟล์ไปเก็บใว้ในฐานข้อมูล ให้ทำการ Add ชื่อไฟล์ filename_new ลงในฐานข้อมูล จากนั้นเมื่อต้องการนำรูปภาพมาแสดง
' ให้อ้างอิง Path Picture/filename_new
uploadfile.Close
set fs=Nothing
Else
%>
กรุณาเลือกไฟล์นามสกุล .gif , .jpg , หรือ jpeg เท่านั้น
<br>
กลับไปแก้ไข <a href="javascript:history.back()">คลิกที่นี่</a>
<%
End If
Else
%>
ขนาดไฟล์เกิน 80 KB กรุณาเลือกไฟล์ใหม่<br>
<br>
กลับไปแก้ไข <a href="javascript:history.back()">คลิกที่นี่</a>
<%
End If
%>
</body>
</html>
สวัสดีครับ โค้ดดังกล่าวทั้งหมดผมได้มาจากบทเรียนASPครับ พอดีใน sample1.asp ผมได้ทำการเพิ่ม textbox เข้าไปอีกหนึ่งอัน แล้วผมจะทำการรับค่า textbox ที่อยู่ใน sample1.asp ได้ยังไงครับ เมื่ออยู่ใน sample2.asp ช่วยหน่อยครับ Thank you.
Tag : - - - -
|
|
 |
 |
 |
 |
Date :
7 ก.พ. 2548 17:53:02 |
By :
nature_life19 |
View :
3055 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
name=uploaddata.Item("ชื่อ TextBox").Item("value")
|
 |
 |
 |
 |
Date :
7 ก.พ. 2548 18:21:40 |
By :
@W_IN |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Thank
|
 |
 |
 |
 |
Date :
2009-05-24 18:22:51 |
By :
LM |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|