ADesigner
Nov 8th 2005, 9:40 pm
hi all,I try to write some codes for upload files:
what I used is
vbscript
ado.stream
fso
but,I saw that CPU is 90% when I was testing the codes,so can you help me or tell me how to write the codes about upload files or where i need to change in my codes ?:confused:
vectorgraphx
Nov 9th 2005, 5:52 am
Welcome to DP, Adesigner. A few things that will help our members help you:
Clarify things a bit - i.e. did your code do what you expected it to do, or did it error out? Also, what is your code? It's hard to diagnose what might/might not have gone wrong if all we know are the elements you chose to use, but if you provide us with some code samples, we might just be able to help you improve your code.
Are you using a third-party upload script, such as aspupload? or are you trying to write your own upload script? Are you trying to upload images, text files, audio, or what? What file size are these items you are trying to upload? Also, by saying CPU is 90%, are you referring to your client-side CPU, or the server CPU? Either way, what services are eating up your CPU usage at the time?
For starters, answer these questions, and provide code, and we'll see what we can do to help ya out.
Again, welcome to DP!!
VG
ADesigner
Nov 9th 2005, 6:06 pm
yes,I'm sorry for that,so,here is my codes,they can run exactly,
but the latency time is so long(almost 30 min) and the program impropriate the cpu resource more than 70% when i run the codes to upload 3 files (size:1st is 10M,2nd is 8.4M,3th is 43.3M) ,
SO WHAT I NEED is how can i improve the efficiency of the codes!
My Codes:
...@LANGUAGE="VBSCRIPT"...
'=================================================
' upload Test
' 2005-11-07
'
'
'
'=================================================
response.Expires = 0
server.ScriptTimeout = 9999
' //define variable
dim RqData,vbEnter,objStrmForm,objStrmTemp,strListSep, formDictionary,fileDictionary
dim objconn,connstr
dim Tname,Tvalue
dim Fformname,Finfo_txt,Finfo_bin,theFileNum
dim theFileName,theFileName_Ext,theFileMime,theFileSiz e,theFileId,theFileBin,theFilePath
dim theFormName,theFormValue
dim TotalSize,theFileMaxSize
dim errcode,errmsg,intIsFile
dim startp,endp,TempStartp,TempEndp,sLen,cutLen
startp = 0
endp = 0
theFileNum = 0
set formDictionary = server.createobject("scripting.dictionary")
set fileDictionary = server.createobject("scripting.dictionary")
vbEnter = chrb(13) & chrb(10)
vbEnter2 = vbEnter & vbEnter
' //create stream object
set objStrmForm = server.createobject("adodb.stream")
set objStrmTemp = server.createobject("adodb.stream")
with objStrmForm
.type = 1
.mode = 3
end with
' //get the data from the form
objStrmForm.open
objStrmForm.write request.BinaryRead(request.TotalBytes)
objStrmForm.position = 0
' //send the binary data to a variable
RqData = objStrmForm.read
TotalSize = objStrmForm.size
' //get the list separator of the binary data
strListSep = midb(RqData,1,clng(instrb(1,RqData,vbEnter,0) - 1))
' //the length of the list separator
sLen = lenb(strListSep)
' //if the point not beyond the totalsize of the binary data then do
do while endp + 10 < TotalSize
startp = instrb(startp + 1,RqData,strListSep,0) + sLen + 2
endp = instrb(startp,RqData,vbEnter2,0)
if endp = 0 then exit do
cutLen = endp - startp - 1
' //open the temporary stream object
objStrmTemp.type = 1
objStrmTemp.mode = 3
objStrmTemp.open
objStrmForm.position = startp
objStrmForm.copyto objStrmTemp,cutLen
objStrmTemp.position = 0
objStrmTemp.type = 2
Finfo_txt = objStrmTemp.readtext
objStrmTemp.close
endp = startp + cutLen
objStrmForm.position = endp
' //if the data is the binary data of a file
if instr(Finfo_txt,"filename=""") > 0 then
intIsFile = 1
theFileNum = theFileNum + 1
theFormName = getFormName(Finfo_txt)
theFilePath = getFilePath(Finfo_txt)
theFileName = getFileName(theFilePath)
theFileName_Ext = getFileExtName(theFileName)
theFileMime = getFileMime(Finfo_txt)
theFileBin = getFormValue(intIsFile)
fileDictionary.add theFormName,theFileName
fileDictionary.add theFileName & "_path",theFilePath
fileDictionary.add theFileName & "_ext",theFileName_Ext
fileDictionary.add theFileName & "_mime",theFileMime
fileDictionary.add theFileName & "_size",theFileSize
fileDictionary.add theFileName & "_bin",theFileBin
response.write("<br>" & theFormName)
response.write("=")
response.write(theFileSize)
response.write("<br><br><br><br>")
else
intIsFile = 0
theFormName = getFormName(Finfo_txt)
theFormValue = getFormValue(intIsFile)
formDictionary.add theFormName,theFormValue
response.write(theFormName)
response.write("=")
response.write(theFormValue)
end if
loop
RqData = ""
objStrmForm.close()
objconn.close()
fileDictionary.removeall()
formDictionary.removeall()
set fileDictionary = nothing
set formDictionary = nothing
set objStrmForm = nothing
set objconn = nothing
response.write("<br>success! you uploaded " & theFileNum & " files in number!")
' //Subprogram
' //get the name of a form element
function getFormName(strInfo)
dim strStart,strLen,strEnd
strStart = instr(strInfo,"name=""") + 6
strEnd = instr(strStart,strInfo,"""",1)
strLen = strEnd - strStart
getFormName = mid(strInfo,strStart,strLen)
end function
' //get the value of a form element
function getFormValue(isFile)
startp = instrb(endp,RqData,vbEnter2) + 3
endp = instrb(startp,RqData,strListSep) - 3
cutLen = endp - startp
objStrmTemp.type = 1
objStrmTemp.mode = 3
objStrmTemp.open()
objStrmForm.position = startp
objStrmForm.copyto objStrmTemp,cutLen
objStrmTemp.position = 0
if isFile = 0 then
objStrmTemp.type = 2
objStrmTemp.charset = "gb2312"
getFormValue = objStrmTemp.readtext()
else
getFormValue = objStrmTemp.read()
theFileSize = objStrmTemp.size
end if
objStrmTemp.close()
end function
' //get the path of the file uploaded
function getFilePath(strInfo)
dim strStart,strLen,strEnd
strStart = instr(strInfo,"filename=""") + 10
strEnd = instr(strStart,strInfo,"""",1)
strLen = strEnd - strStart
getFilePath = mid(strInfo,strStart,strLen)
end function
' //get the file content type
function getFileMime(strInfo)
dim strStart,strLen,strEnd
strStart = instr(strInfo,"Content-Type: ") + 14
strEnd = len(strInfo) + 1
strLen = strEnd - strStart
getFileMime = mid(strInfo,strStart,strLen)
end function
' //get the short filename of the file uploaded
function getFileName(strInfo)
dim strStart,strLen,strEnd
strStart = instrRev(strInfo,"\") + 1
strEnd = Len(strInfo) + 1
strLen = strEnd - strStart
getFileName = mid(strInfo,strStart,strLen)
end function
' //get the eextended name of file
function getFileExtName(strInfo)
dim strStart,strLen,strEnd
strStart = instrRev(strInfo,".")
strEnd = Len(strInfo) + 1
strLen = strEnd - strStart
getFileExtName = mid(strInfo,strStart,strLen)
end function
' // end
well, Is my arithmetic not good or there's some way more better? I really don't know how should i do to improving my codes,
help!
vBulletin® v3.6.8, Copyright ©2000-2008, Jelsoft Enterprises Ltd.