0

How do I get the full path file from <input type="file />?

I kept getting C:\fakepath\[filename]

Here 's my script

$(function(){
$('button').click(function(){
alert($('input#path').val());
});
});

<input type="file" id="path" />
<button>Read</button>

What I want to do is to pass the file path from Javascript to PHP then read/rewrite it.


UPDATE: I tried the following but I still get the fakepath. Im using Chrome.

$(function(){
$('button').click(function(){
$.post(
'test2.php', {
path: $('input#path').val()
}, function(data){
alert(data);
}
);
});
});

test2.php

<?php
echo $_POST['path'];
?>
JohnSmith
  • 1,457
  • 2
  • 18
  • 27
  • 1
    It't not allowed to read the filepath from the input field. You get a temporary path to not compromise the users file system. I think you might use HTML5 File API for newer browsers to be able to read the file, otherwise, you have to process it on the server. – ThoKra Aug 05 '12 at 07:57
  • I tried sending it into PHP using $.post(), I still get the fake path – JohnSmith Aug 05 '12 at 10:56

1 Answers1

1

You just need to post the data with javascript using ajax. The "fakepath" is a security feature by the browser.

How to resolve the C:\fakepath?

Community
  • 1
  • 1
jeremy
  • 9,965
  • 4
  • 39
  • 59