469,282 Members | 1,948 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,282 developers. It's quick & easy.

Javascript Finding an Image's property.

3
Hi All,
Im new to the web development.... Here I wanna know some codes which support the following criteria..
1) Restricting other files except image files.
2) Restricting image file with the specified length(length in bytes)
3) Restricting image file with the specified Size(Dimensions)

I could able to manage the above criterias through javascript...But the problem is im not able to generalize the code with all the browsers (i.e., Working in IE, but not in Firefox). :confused:

Could any one tell me the solution
Jul 31 '06 #1
5 4295
iam_clint
1,208 Expert 1GB
Yes i could tell you the solution more then likely if you post your question in a better way i am not fully understanding what you are wanting it to do. restrict everything but images, the image size and the image dimensions.

what do you mean by restrict?
Aug 1 '06 #2
jarjis
3
Hi,
Thanks for the reply...

We have to restrict the user to upload/select/browse other files(such as txt, doc) through browse field...Moreover I have to restrict the user to donot upload the image which is different in size(dimension) and in length(bytes). Looking for the reply...Thank you.... :)
Aug 1 '06 #3
iam_clint
1,208 Expert 1GB
What code are you using for the upload.. you can do everything your talking about in PHP and ASP, javascript wouldn't be practical for this application because javascript is client side and anyone determined will beable to upload any file they want... so server side would be the best way to go other then that for javascript look into javscript image.fileSize for bytes and image.width and image.height...
Aug 1 '06 #4
jarjis
3
Hi
Here i wanted to do that through client side script. Is this possible to acheive it?

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;
}
}

in this code im not able to get the file size in FIREFOX

Thank you.
Aug 2 '06 #5
acoder
16,027 Expert Mod 8TB
Hi
Here i wanted to do that through client side script. Is this possible to acheive it?

[snip]

in this code im not able to get the file size in FIREFOX

Thank you.
Firefox (correctly) does not allow access to local files. However, I would have hoped that harmless files such as image files would be allowed...
Nov 24 '06 #6

Post your reply

Sign in to post your reply or Sign up for a free account.

By using this site, you agree to our Privacy Policy and Terms of Use.