<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 p_w_picpath dimensions"
ONCLICK="checkImageDimensions(this.form.fileName.value)"
>
</FORM>
</BODY>
</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 p_w_picpath dimensions"
ONCLICK="checkImageDimensions(this.form.fileName.value)"
>
</FORM>
</BODY>
</HTML>
转载于:https://blog.51cto.com/wangqinglin/78578