PDA

View Full Version : javascript image format



hemi519
12-31-2010, 09:19 PM
Hi All,

Can anyone help me in this issue. In the below code i am able toselect a image
<input type=file onChange="load_image(this.id,'jpg');">


when i select a image i should get the format of image in the load image function. For now i am doing manually keeping it to 'jpg'. How can i get it dynamically

jscheuer1
01-01-2011, 08:34 AM
There's no reliable way to get the file type. On the server side there are better tools available. But even those aren't infallible. In javascript about the best you could do is grab the filename and parse its extension:


<input type=file onchange="load_image(this.id,this.value.substring(this.value.lastIndexOf('.') + 1));">