Results 1 to 2 of 2

Thread: javascript image format

  1. #1
    Join Date
    Nov 2010
    Posts
    115
    Thanks
    27
    Thanked 0 Times in 0 Posts

    Default javascript image format

    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

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    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:

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

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. The Following User Says Thank You to jscheuer1 For This Useful Post:

    hemi519 (01-01-2011)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •