2007-12-04

* http : how can know http form file upload size before file sending? (Check file size before upload)

if your send file input page like this.

<FORM ACTION="http://somehost/get.php" ENCTYPE="multipart/form-data" METHOD=POST>
What is your name? <INPUT TYPE=TEXT NAME=submitter>
What files are you sending? <INPUT TYPE=FILE NAME=pics>
<input type='submit'>
</FORM>

but the file get.php is not present..
what happen??
normlay..

your browser send all of your choosen file(it 700MB)..
and somehost response to your browser..
"Sorry, the page you requested was not found." <== 404 error

so...
you can't know file size before all file sended.

but

you can know file size before file sneding....

'windows iis http server' is soluntion..
iis is default do not have fileupload function..
so iis server disconnect socket when browser upload file longtime.

upload using put.html to up.asp
(up.asp page return error, socket disconnect but c:\temp\fileNo123\23444 file created)
and
call get.asp?fileSeq=fileNo123

you can get file size which you uploaded.
(size is some diffrent original file, but is not problem)

put.html
////////////////////
<form method='post' action='up.asp?fileNo123' enctype='multipart/form-data'>
<input type='file' name='upfile'>
<input type='submit' value='send'>
</form>
////////////////////

up.asp
////////////////////
<% option explicit %>
<%
Server.ScriptTimeOut = 7200

dim fileSize : fileSize = trim(request.ServerVariables("CONTENT_LENGTH"))
dim fileSeq : fileSeq = trim(request.ServerVariables("QUERY_STRING"))

dim fileName, folderName
folderName = "c:\temp\" & fileSeq
fileName = folderName & "\" & fileSize

'response.write("<hr>")
'response.write(fileSize)
'response.write("<hr>")
'response.write(fileSeq)
'response.write("<hr>")
'response.write(folderName)
'response.write("<hr>")
'response.write(fileName)
'response.write("<hr>")
'response.end()

dim fso
set fso=createobject("scripting.filesystemobject")
'{
  if not fso.FolderExists(folderName) then
    fso.createfolder folderName
  end if

  fso.CreateTextFile fileName, true
'}
set fso=nothing
%>
////////////////////

get.asp
////////////////////
<% option explicit %>
<%
dim fileSeq : fileSeq = trim(request.QueryString("fileSeq"))

dim folderName
folderName = "c:\temp\" & fileSeq

'response.write("<hr>")
'response.write(folderName)
'response.end()

Dim fso, item, fileSize
set fso=createobject("scripting.filesystemobject")
'{
  for each item in fso.GetFolder(folderName).files
    if isnumeric(item.Name) then fileSize = item.Name
 next
'}
set fso = nothing

response.write fileSize
%>
////////////////////

** origin from psseo

Labels: , , , , , , , ,

0 Comments:

Post a Comment

<< Home