get original file path of uploaded file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ciary
    Recognized Expert New Member
    • Apr 2009
    • 247

    get original file path of uploaded file

    hey all,

    i've a question about file upload. i want to save the original filepath as it was on the users PC (eg 'C:\Documents and settings\guest\ documents\test. txt') i cant seem to find the right way. i already tried 2 ways:

    1) using $_FILES['name'] but this only returns the name (test.txt)
    2)using javascript and filefield.value . this gave the same problem as the previous method

    does anyone know if, and, if yes, how this can be done?

    EDIT:
    method nr2, is usable in IE, chrome and Opera. as far as i know, only firefox wont return the full path.

    anyone got any ideas how i could get it working there?
  • code green
    Recognized Expert Top Contributor
    • Mar 2007
    • 1726

    #2
    1) using $_FILES['name'] but this only returns the name (test.txt)
    Isn't 'name' in this instance the HTML name defined on the web-form
    Code:
    <br><input type="file" name="upload">
    For the full path you need $_FILES['upload']['name']
    Although I am pretty sure that if the browser wants to hide this information from the server it will

    Comment

    • Ciary
      Recognized Expert New Member
      • Apr 2009
      • 247

      #3
      like i said. it's possible to read the file-field in javascript.
      Code:
      alert(document.getElementById('myfilefield').value);
      and as i said, this will return C:\my\path\test .txt in IE, Chrome and Opera. but FF will still return test.txt.

      you're right about the $_FILES['upload']['name']. i forgot to type it :).

      about FF, it's probably for security reason, the path isn't shown. i'll have to put a warning on my page, it doesn't work with mozilla.

      Comment

      Working...