2008-07-29

* 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
'}
%>
//////////////

Labels: , , , , , , , ,

2008-07-28

* diff style.display, style.visibility

<html>
<head>
<script type='text/javascript'>
function func1(type)
{
document.all['obj1'].style.display= type;
}

function func2(type)
{
document.all['obj2'].style.visibility = type;
}
</script>
</head>
<body>

<hr>
<span id='obj1'><table border=1 width=100 height=20><tr><td align='center'>obj1</td></tr></table></span>
<hr>
<span id='obj2'><table border=1 width=100 height=20><tr><td align='center'>obj2</td></tr></table></span>
<hr>

<table border=0>
<tr><td><a href="javascript:func1('none')">display none</a></td><td>  </td><td><a href="javascript:func2('hidden')">visibility hidden</a></td></tr>
<tr><td><a href="javascript:func1('block')">display block</a></td><td>  </td><td><a href="javascript:func2('visible')">visibility visible</a></td></tr>
</table>

</body>
</html>