Closed Thread Icon

Preserved Topic: Image size in "input type=file" (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=18420" title="Pages that link to Preserved Topic: Image size in &amp;quot;input type=file&amp;quot; (Page 1 of 1)" rel="nofollow" >Preserved Topic: Image size in &quot;input type=file&quot; <span class="small">(Page 1 of 1)</span>\

 
Wakkos
Maniac (V) Mad Scientist

From: Azylum's Secret Lab
Insane since: Oct 2000

posted posted 09-10-2002 09:33

IS it possible to know the size of an image in an <input type=file name=img1 size=30>?

I want to show the user, the size the image he is inputing is!
Is that possible? Before submitting?

DmS
Paranoid (IV) Inmate

From: Sthlm, Sweden
Insane since: Oct 2000

posted posted 09-10-2002 10:17

As in size, do you mean dimensions (height and width) or do you mean filesize?
I havn't found any way to get dimensions or filesize from javascript on the client, but let's hope someone else has

If it's dimensions you want, I suppose you could use the input-fields path (value) to place an image inside a hidden div and then collect the height and width from that (just an idea, havn't tested it though)
/Dan

{cell 260}
-{ a vibration is a movement that doesn't know which way to go }-

Wakkos
Maniac (V) Mad Scientist

From: Azylum's Secret Lab
Insane since: Oct 2000

posted posted 09-10-2002 10:33

Cool!
but I'm asking for the filesize

*Sits besides DmS waiting*

Coffe?

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 09-10-2002 13:05

No, I'm pretty sure you can't get any information about the file from Javascript.

Wakkos
Maniac (V) Mad Scientist

From: Azylum's Secret Lab
Insane since: Oct 2000

posted posted 09-10-2002 13:37

Period.

Thanks Slime

Pugzly
Paranoid (IV) Inmate

From: 127.0.0.1
Insane since: Apr 2000

posted posted 09-10-2002 14:38

You need to check it server-side once it's uploaded.

InI
Paranoid (IV) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 09-10-2002 14:47

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

DmS
Paranoid (IV) Inmate

From: Sthlm, Sweden
Insane since: Oct 2000

posted posted 09-10-2002 14:59

Woops... I guess you can after all
(No idea on how supported it is though)

Was over at the GurusNetwork (this thread: http://www.gurusnetwork.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic;f=9;t=000289;p=2 ) and saw a nifty little bookmarklet that Pugzly has put together:

It seems that you can get size in kb width and height in px through javascript after all...

Do this:

code:
function imagesCheck(){
var y = document.images;
for (i=0;i<y.length;i++){
alert("image "+i+" size in kb: " +(y[i].fileSize)*1);
alert("image "+i+" height in px: " +(y[i].height)*1);
alert("image "+i+" width in px: " +(y[i].width)*1);
}
}



then call it on load or in a link, whatever. It will loop the images array and alert you with the info you need.
I'm pretty sure you must grab this after everything is loaded though.

So, if you add an image in a similar way that I suggested in the first answer to the page, it will end up last in the document.images[] array, then pick what you need from there.

Hey, just saw Pugzly got in a post before this, hope you don't mind me pointing
/Dan

<edit> Well, InI got in there too... need to reply...
Well, If you are using an input type file, you are locally on the users machine, so you can actually load the image into the document.images array as soon as the user picks a file, just call it "onchange" in the form-field, from there you can alert the user, check for allowed size/dimensions whatever
<endedit>

{cell 260}
-{ a vibration is a movement that doesn't know which way to go }-

[This message has been edited by DmS (edited 09-10-2002).]

[This message has been edited by DmS (edited 09-10-2002).]

[This message has been edited by DmS (edited 09-10-2002).]

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 09-10-2002 15:03

Wow, interesting. Generally you can't do much with the <input> element with javascript, since it opens the user's computer up to security risks.

Wakkos
Maniac (V) Mad Scientist

From: Azylum's Secret Lab
Insane since: Oct 2000

posted posted 09-10-2002 15:15

I got to this:

code:
function verfoto()	{
var lafoto = new Image();
lafoto.src = document.getElementById("archivo").value;
document.getElementById("imagen_quien").src = lafoto.src;


}


and then in the input file:

code:
<INPUT id=archivo type=file onchange=verfoto() size=65 name=archivo>
<IMG id=imagen_quien src="#" name=imagen_quien>



It was a little complicated for me, but I think that I could make it work for every input (i have 20 in one single page)

What I dunno is to get the filesize with that.

I'm looking right now in the DmS link.....


[This message has been edited by Wakkos (edited 09-10-2002).]

InI
Paranoid (IV) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 09-10-2002 15:27

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

InI
Paranoid (IV) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 09-10-2002 15:44

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

Wakkos
Maniac (V) Mad Scientist

From: Azylum's Secret Lab
Insane since: Oct 2000

posted posted 09-10-2002 15:50

I was making exactly that:

code:
function verfoto()	{
var lafoto = new Image();
lafoto.src = document.getElementById("archivo").value;
document.getElementById("imagen_quien").src = lafoto.src;

setTimeout("alert(document.images['imagen_quien'].fileSize);",1000);
}



good thing to be here!!!

InI
Paranoid (IV) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 09-10-2002 15:58

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

Wakkos
Maniac (V) Mad Scientist

From: Azylum's Secret Lab
Insane since: Oct 2000

posted posted 09-10-2002 16:19

I have Opera 5.12 and Mozilla 1.01 (.01? I don't want to open it again please!) and does not work neither in Mozilla nor Opera....

I'm sad now.

InI
Paranoid (IV) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 09-10-2002 16:21

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

Wakkos
Maniac (V) Mad Scientist

From: Azylum's Secret Lab
Insane since: Oct 2000

posted posted 09-10-2002 16:28

When I made the test, I made it with a valid mage....

« BackwardsOnwards »

Show Forum Drop Down Menu