 |
|
ต้องการเปลี่ยนชื่อรูปภาพที่ upload ลงในเว็บคับ |
|
 |
|
|
 |
 |
|
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
%>
outputfile.asp
<!--#include file="upload.asp"-->
<%
len1=Len(request("url"))-InstrRev(request("url"),"/")
pathinfo=Server.mappath(Request.ServerVariables("PATH_INFO"))
pathEnd = Len(pathinfo)-len1
filepath=left(pathinfo,pathEnd) & "image\"
Response.Expires=0
Response.Buffer =TRUE
Response.Clear
byteCount = Request.TotalBytes
RequestBin = Request.BinaryRead(byteCount)
Dim UploadRequest
Set UploadRequest = CreateObject("Scripting.Dictionary")
BuildUploadRequest RequestBin
'email = UploadRequest.Item("email").Item("Value")
detail = UploadRequest.Item("detail").Item("Value")
subjectID = UploadRequest.Item("subjectID").Item("Value")
contentType = UploadRequest.Item("blob").Item("ContentType")
if left(ContentType,5) <>"image" then
response.write "<center><b> Upload ä´E੾ÒÐÃÙ»ÀÒ¾à·èÒ¹Ñé¹</b></center>"
response.end
end if
filepathname = UploadRequest.Item("blob").Item("FileName")
filename = Right(filepathname,Len(filepathname)-InstrRev(filepathname,"\"))
value = UploadRequest.Item("blob").Item("Value")
response.write "Type: "&contentType & "<br>"
'-------------------- upload to server ------------------------
Set ScriptObject = Server.CreateObject("Scripting.FileSystemObject")
response.write "Filename: " & filename & "<br>"
response.write "Path: " & filepath & "<br>"
Set fileObj = ScriptObject.CreateTextFile(filepath & filename)
For i = 1 to LenB(value)
fileObj.Write chr(AscB(MidB(value,i,1)))
Next
fileObj.Close
%>
ช่วยแก้ไขโค้ดให้ผมหน่อครับ ผม upload รูปลงเว็บ แต่อยากเปลี่ยนชื่อของรูปที่จะ upload ลงเว็บไม่ให้ชื่อซำกันคับและอยากถามว่า โค้ดที่ผมใช้ upload รูปภาพนี้ ควรเพิ่มเติมอะไรอีกบ้างหรือป่าวคับ ถ้าผู้รู้ทราบช่วยปรับปรุงให้ผมด้วยนะครับ ขอบคุณมากครับ
Tag : - - - -
|
|
 |
 |
 |
 |
Date :
4 ก.พ. 2548 14:46:44 |
By :
nature_life19 |
View :
3747 |
Reply :
3 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ใช้เวลามาจัดการเกี่ยวกับตัวนี้ครับ
จะได้ข้อมูลภาพที่ชื่อไม่ซ้ำกันครับ
ช่น
TimeNow=Replace(Time, ":", "")
' จะได้เวลาปัจจบันมาแทนชื่อไฟล์ครับเช่น 154400filename.gif
filename_new=TimeNow&Mid(filename,pos_filebegin+1,pos_fileend-pos_filebegin)
|
 |
 |
 |
 |
Date :
4 ก.พ. 2548 18:29:08 |
By :
@W_IN |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ถ้าจำกำหนดที่อยู่ในการจัดเก็บจะต้องแก้หรือเพิ่มตรงไหนครับ .. เช่น D:\Temporary\New Folder\1234.jpg
|
 |
 |
 |
 |
Date :
2015-05-23 10:30:39 |
By :
ณัฐชนนท์ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|