Help with grabbing a file name

Discussion in 'JavaScript' started by chrisj, Oct 7, 2014.

  1. #1
    In a php upload Form when a User chooses an image file to upload,
    the name of the file appears next to the Choose File button (see attachment)
    is it possible to grab that file name, add it to the page, and proceed with completing the Form
     

    Attached Files:

    chrisj, Oct 7, 2014 IP
  2. ByteChef

    ByteChef Active Member Affiliate Manager

    Messages:
    64
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    75
    #2
    ByteChef, Oct 7, 2014 IP
  3. Piotr Aszoff

    Piotr Aszoff Active Member

    Messages:
    38
    Likes Received:
    3
    Best Answers:
    2
    Trophy Points:
    53
    #3
    #chrisj, I do not know what you are trying to achieve, but if you want to add the file to the page, and show it to users before submiting the form, then you probably should use FileReader (html5 api), which will allow you to catch the file on the frontend side of a page.

    Regards, Piotr
     
    Piotr Aszoff, Oct 8, 2014 IP
  4. jasdews

    jasdews Greenhorn

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    21
    #4
    If you use JQuery the following command will give you the filename. The syntax fakepath is common
    var filename = $('input[type=file]').val().replace(/C:\\fakepath\\/i, '')
     
    jasdews, Oct 8, 2014 IP