JS에서 업로드 파일 크기를 가져오는 방법
function getFileSize(filePath)
{
var fso = new ActiveXObject("Scripting.FileSystemObject");
alert(" :"+fso.GetFile(filePath).size);
}
</script>
<body>
<INPUT TYPE="file" NAME="file" SIZE="30" onchange="getFileSize(this.value);">
</body>
<script type="text/javascript">
function getFileSize(filePath)
{
var image = new Image();
image.dynsrc = filePath;
alert(image.fileSize);
}
</script>
<body>
<INPUT TYPE="file" NAME="file" SIZE="30" onchange="getFileSize(this.value)">
</body> 첫 번째 메서드는 Automation 오류를 보고합니다.IE8에서 다운로드하려면 실행을 허용해야 합니다.
두 번째 방법은 IE6 아래에 있습니다. IE8 아래에 "dynsrc 속성을 설정할 수 없습니다. 접근을 거부합니다."오류, 대문자 DYNSRC를 사용하면 오류가 발생하지 않지만 뒤에 있는 fileSize는 사용할 수 없습니다.
관련 기사:http://www.csharpwin.com/dotnetspace/12652r1167.shtml
원문 주소:http://hi.baidu.com/_feiying/blog/item/dac89227fc52a008908f9d0e.html/cmtid/78efc59bb20d36bbc8eaf445
:<input type="text" size="4" value="10" name="fileSizeLimit" id="fileSizeLimit"/> K
<input type="file" name="file1" id="file1" size="40" onchange="changeSrc(this)"/>
<br>
<img src=http://blog.xunuo.com/blog/images/icons/23.gif id="fileChecker" alt="test"/>
<script type="text/javascript">
var oFileChecker = document.getElementById("fileChecker");
function changeSrc(filePicker)
{
oFileChecker.src = filePicker.value;
}
oFileChecker.onreadystatechange = function ()
{
if (oFileChecker.readyState == "complete")
{
checkSize();
}
}
function checkSize()
{
var limit = document.getElementById("fileSizeLimit").value * 1024;
if (oFileChecker.fileSize > limit)
{
alert("too large");
}
else
{
alert("ok");
}
}
</script> 위의 방법은 취할 만한 점이 있다
관련 기사:http://www.csharpwin.com/dotnetspace/12652r1167.shtml
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Java/PDF에서 이미지 바꾸기우리 모두 알다시피 PDF는 편집하기 어려운 일종의 문서 형식입니다. 그러나 다른 사람으로부터 PDF 문서를 받을 때 문서의 이미지를 새 이미지로 바꾸는 등 약간의 수정이 필요할 수 있습니다. 이 문서에서는 Java...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.