用javaScript获取文件,jpg图片大小
2010-09-14 13:17:12 来源:WEB开发网<HTML>
<HEAD>
<SCRIPT>
function getImageDimension (imgURL, loadHandler) {
var img = new Image();
img.onload = loadHandler;
if (document.layers
&& location.protocol.toLowerCase() != 'file:'
&& navigator.javaEnabled())
netscape.security.PrivilegeManager.enablePrivilege(
'UniversalFileRead'
);
img.src = imgURL;
}
function getFileSize (fileName) {
if (document.layers) {
if (navigator.javaEnabled()) {
var file = new java.io.File(fileName);
if (location.protocol.toLowerCase() != 'file:')
netscape.security.PrivilegeManager.enablePrivilege(
'UniversalFileRead'
);
return file.length();
}
else return -1;
}
else if (document.all) {
window.oldOnError = window.onerror;
window.onerror = function (err) {
if (err.indexOf('utomation') != -1) {
alert('file access not possible');
return true;
}
else
return false;
};
var fso = new ActiveXObject('Scripting.FileSystemObject');
var file = fso.GetFile(fileName);
window.onerror = window.oldOnError;
return file.Size;
}
}
function showImageDimensions () {
alert(this.width + 'x' + this.height);
}
</SCRIPT>
<SCRIPT>
function checkImageDimensions (fileName) {
var imgURL = 'file:///' + fileName;
getImageDimension(imgURL, showImageDimensions);
}
</SCRIPT>
</HEAD>
<BODY>
<FORM NAME="formName">
<INPUT TYPE="file" NAME="fileName">
<BR>
<INPUT TYPE="button" VALUE="check file size"
ONCLICK="alert(getFileSize(this.form.fileName.value))"
>
<BR>
<INPUT TYPE="button" VALUE="check image dimensions"
ONCLICK="checkImageDimensions(this.form.fileName.value)"
>
</FORM>
</BODY>
</HTML>
Tags:javaScript 获取 文件
编辑录入:爽爽 [复制链接] [打 印]- ››JavaScript项目优化总结
- ››获取Android手机型号,系统版本,App版本号等信息
- ››获取Windows xp系统高权限无需注销用户
- ››JavaScript 判断浏览器是否支持SVG方法
- ››javascript自动改变文字大小和颜色的效果
- ››Javascript中产生固定结果函数的优化
- ››javascript 系统文件夹文件操作
- ››获取checkedListBox 选中的项并且移动
- ››Javascript 遮罩层和加载效果
- ››javascript创建二维码(Table/Canvas两种方式)
- ››JavaScript定时器详解
- ››javascript中可以直接写php代码
赞助商链接