473,323 Members | 1,589 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

Image upload dimension check

Hi,

I'm trying to use the following code (found online - can't remember where)
to validate images being uploaded to my server:

function checkImageUpload (fileName) {
if (document.layers && location.protocol.toLowerCase() != 'file:' &&
navigator.javaEnabled()){
netscape.security.PrivilegeManager.enablePrivilege ('UniversalFileRead');
}
var msg = '';
var img = new Image();
img.src = 'file:///' + fileName;
if (img.width != 180 || img.height != 90){
msg = "The selected image dimensions are not valid. The image must be 180
x 90 pixels.\n\n";
msg = msg + "Your selected image dimensions are " + img.width + " x " +
img.height;
alert('The required information is incomplete or contains
errors:\t\t\t\t\t\n\n'+msg);
return false
} else {
return true
}
}

Trouble is it won't work in Netscape. I get 0 x 0 pixels reported as being
the image size although the if(document.layers... line should be dealing
with Netscape issues (I think)...

What I ultimately want is to be able to make this script cross browsers
compatible and cross platform is possible...

Can anyone help me out? I'd prefer not to have to revert to validating the
file AFTER having uploaded it...

I also need to be able to make the script only accept jpg's and gif's - is
there an easy method of achieving this?

Cheers,

GP
Jul 20 '05 #1
4 13954

"Gianpiero Colagiacomo" <gp@1lg.com> wrote in message
news:bj**********@lacerta.tiscalinet.it...
| Hi,
|
| I'm trying to use the following code (found online - can't remember where)
| to validate images being uploaded to my server:
|
| function checkImageUpload (fileName) {
| if (document.layers && location.protocol.toLowerCase() != 'file:' &&
| navigator.javaEnabled()){
| netscape.security.PrivilegeManager.enablePrivilege ('UniversalFileRead');
| }

That is some bizarre logic. What does layers have to do with whether the
security object is present? FYI layers are only present in NS4 and OmniWeb
(at current count.)

| var msg = '';
| var img = new Image();
| img.src = 'file:///' + fileName;
| if (img.width != 180 || img.height != 90){
| msg = "The selected image dimensions are not valid. The image must be
180
| x 90 pixels.\n\n";

No idea why NS would come up with 0x0. Have you tried using a dummy image
instead of creating the object on the fly? In fact, that is almost
certainly it as the created image is hidden.

I would validate this on the server-side anyway. None of this stuff will
work if script is turned off!


Jul 20 '05 #2
Nobody - Thanks I'll try using a dummy image and see if that solves it...

As for the 'bizarre logic' - as I said before the script came from someone
else - I only altered it a little and that line was left alone as I had no
idea what it was attempting to do...

What would you suggest for checking if the security object IS present (cross
browser)?

Cheers,

GP

"Nobody" <no**@nope.net> wrote in message
news:Lx*************@fe3.columbus.rr.com...

"Gianpiero Colagiacomo" <gp@1lg.com> wrote in message
news:bj**********@lacerta.tiscalinet.it...
| Hi,
|
| I'm trying to use the following code (found online - can't remember where) | to validate images being uploaded to my server:
|
| function checkImageUpload (fileName) {
| if (document.layers && location.protocol.toLowerCase() != 'file:' &&
| navigator.javaEnabled()){
| netscape.security.PrivilegeManager.enablePrivilege ('UniversalFileRead'); | }

That is some bizarre logic. What does layers have to do with whether the
security object is present? FYI layers are only present in NS4 and OmniWeb (at current count.)

| var msg = '';
| var img = new Image();
| img.src = 'file:///' + fileName;
| if (img.width != 180 || img.height != 90){
| msg = "The selected image dimensions are not valid. The image must be
180
| x 90 pixels.\n\n";

No idea why NS would come up with 0x0. Have you tried using a dummy image
instead of creating the object on the fly? In fact, that is almost
certainly it as the created image is hidden.

I would validate this on the server-side anyway. None of this stuff will
work if script is turned off!

Jul 20 '05 #3
"Gianpiero Colagiacomo" <gp@1lg.com> writes:
I'm trying to use the following code (found online - can't remember where)
Never a good sign.
to validate images being uploaded to my server:

function checkImageUpload (fileName) {
if (document.layers && location.protocol.toLowerCase() != 'file:' &&
navigator.javaEnabled()){
netscape.security.PrivilegeManager.enablePrivilege ('UniversalFileRead');
}
I'll assume this works for Netscape 4 with a non-file-protocol and
java enabled.

img.src = 'file:///' + fileName;
if (img.width != 180 || img.height != 90){
Here is a serious problem. Images are loaded asynchronelously. A local
file might be loaded fast enough that you this works ... most of the
time, but you should always wait for the image to load.

One way to do that, is to put the rest of the code in the image's onload
handler, and add an onerror handler for the case where it doesn't work.
Trouble is it won't work in Netscape.
Which Netscape?
There are Netscape 4 and Netscape 6/7, which are two completely unrelated
browsers.
What I ultimately want is to be able to make this script cross browsers
compatible and cross platform is possible...
Good luck. I don't think there is any way my browser will let you read
a local file.
I also need to be able to make the script only accept jpg's and gif's - is
there an easy method of achieving this?


No. You can probably check the filename's extension, but that proves nothing.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #4
Ok guys - I get it - check the dimensions in server-side

Thanks...

BTW Jim Ley - your were right - I tried using settimeout on the dimension
check and it worked fine in NN7 and IE5.5. I didn't realise you could set
an onload handler which obviously is the better method.

GP

"Lasse Reichstein Nielsen" <lr*@hotpop.com> wrote in message
news:ek**********@hotpop.com...
"Gianpiero Colagiacomo" <gp@1lg.com> writes:
I'm trying to use the following code (found online - can't remember where)

Never a good sign.
to validate images being uploaded to my server:

function checkImageUpload (fileName) {
if (document.layers && location.protocol.toLowerCase() != 'file:' &&
navigator.javaEnabled()){
netscape.security.PrivilegeManager.enablePrivilege ('UniversalFileRead'); }


I'll assume this works for Netscape 4 with a non-file-protocol and
java enabled.

img.src = 'file:///' + fileName;
if (img.width != 180 || img.height != 90){


Here is a serious problem. Images are loaded asynchronelously. A local
file might be loaded fast enough that you this works ... most of the
time, but you should always wait for the image to load.

One way to do that, is to put the rest of the code in the image's onload
handler, and add an onerror handler for the case where it doesn't work.
Trouble is it won't work in Netscape.


Which Netscape?
There are Netscape 4 and Netscape 6/7, which are two completely unrelated
browsers.
What I ultimately want is to be able to make this script cross browsers
compatible and cross platform is possible...


Good luck. I don't think there is any way my browser will let you read
a local file.
I also need to be able to make the script only accept jpg's and gif's - is there an easy method of achieving this?


No. You can probably check the filename's extension, but that proves

nothing.
/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'

Jul 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Beowulf | last post by:
Hi Guru's, I have a query regarding using PHP to maintain a user profiles list. I want to be able to have a form where users can fill in their profile info (Name, hobbies etc) and attach an...
3
by: dave | last post by:
Hello there, I am at my wit's end ! I have used the following script succesfully to upload an image to my web space. But what I really want to be able to do is to update an existing record in a...
13
by: Neo Geshel | last post by:
I have examined about 80+ different upload scripts on the 'net, both in VB and C#, and none seem to do what I need them to do. Perhaps someone here can point me somewhere that Google hasn't...
15
by: David Lozzi | last post by:
Howdy, I have a function that uploads an image and that works great. I love ..Nets built in upload, so much easier than 3rd party uploaders! Now I am making a public function that will take the...
11
by: Richard | last post by:
All I want to do is to read a list of the image files in my folder and display them on a page. That way I don't have to re-write the page, I can just upload extra images. I don't need fancy...
14
by: =?Utf-8?B?U2FtdWVs?= | last post by:
Hi, I have a web app that allows others to upload files, and the problem is that if I allow users to upload image files, fake image can be uploaded and cause XSS issues. In the app, I do...
7
by: xx75vulcan | last post by:
Hi, I've got a PHP Upload Form that works great, unless that is, the image your uploading has been modified through a photo editing software. Example: if I upload the image straight from a...
1
by: sravani1 | last post by:
This code runs like when i submit the form it takes the image and displayed and top of the image a map will displayed. But actually i want that when i give the image it checks the location in the map...
1
by: chennaibala | last post by:
can any one send me mutiple image upload program and save the file name with extension in mysql table.we must cheak uploaded file type like bmp or any image file while uploading. i develop...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.