* Check file size before upload ?
http://tiptipz.blogspot.com/2007/12/http-how-can-know-http-form-file-upload.html
exgample
//// 1.asp ///
<% option explicit %>
<%
Dim myIP
myIP = Request.ServerVariables("REMOTE_ADDR")
myIP = Replace(myIP, ".", "")
%>
<html>
<head></head>
<body>
<script type='text/javascript'>
var timerID = null;
function setSize()
{
var URL = '3.asp?fileSeq=<%=myIP%>';
filesize.location.href = URL;
}
function clearSize()
{
clearInterval(timerID);
}
function fileSend()
{
timerID = setInterval('setSize()', 1000);
var URL = '2.asp?<%=myIP%>';
var zForm = document.zform;
zForm.action = URL;
zForm.target = 'upcheck';
zForm.submit();
}
</script>
<iframe name='upcheck' width=0 height=0 scrolling=no frameborder=0></iframe>
<iframe name='filesize' width=0 height=0 scrolling=no frameborder=0></iframe>
<form name='zform' method='post' action='javascript:fileSend();' enctype='multipart/form-data'>
<input type='file' name='upfile'>
<input type='submit' value='check'>
</form>
file sieze : <span id='thissize'></span>
</body>
</html>
//////////////
//// 2.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
else
fso.DeleteFolder folderName
end if
fso.CreateTextFile fileName, true
'}
set fso=nothing
%>
//////////////
//// 3.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
fileSize = 0
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
if fileSize > 0 then
'{
%>
<html>
<head></head>
<body leftmargin=0 topmargin=0>
<script type='text/javascript'>
parent.document.all['thissize'].innerHTML = '<%=fileSize%>';
parent.clearSize();
</script>
</html>
<%
end if
'}
%>
//////////////
exgample
//// 1.asp ///
<% option explicit %>
<%
Dim myIP
myIP = Request.ServerVariables("REMOTE_ADDR")
myIP = Replace(myIP, ".", "")
%>
<html>
<head></head>
<body>
<script type='text/javascript'>
var timerID = null;
function setSize()
{
var URL = '3.asp?fileSeq=<%=myIP%>';
filesize.location.href = URL;
}
function clearSize()
{
clearInterval(timerID);
}
function fileSend()
{
timerID = setInterval('setSize()', 1000);
var URL = '2.asp?<%=myIP%>';
var zForm = document.zform;
zForm.action = URL;
zForm.target = 'upcheck';
zForm.submit();
}
</script>
<iframe name='upcheck' width=0 height=0 scrolling=no frameborder=0></iframe>
<iframe name='filesize' width=0 height=0 scrolling=no frameborder=0></iframe>
<form name='zform' method='post' action='javascript:fileSend();' enctype='multipart/form-data'>
<input type='file' name='upfile'>
<input type='submit' value='check'>
</form>
file sieze : <span id='thissize'></span>
</body>
</html>
//////////////
//// 2.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
else
fso.DeleteFolder folderName
end if
fso.CreateTextFile fileName, true
'}
set fso=nothing
%>
//////////////
//// 3.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
fileSize = 0
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
if fileSize > 0 then
'{
%>
<html>
<head></head>
<body leftmargin=0 topmargin=0>
<script type='text/javascript'>
parent.document.all['thissize'].innerHTML = '<%=fileSize%>';
parent.clearSize();
</script>
</html>
<%
end if
'}
%>
//////////////
Labels: asp, before, checking, file, filesize, form, http, size, upload