-1

enter image description here

I want the full path of a selected image to be displayed once Choose File button is clicked. Any idea on how to do that?

curveball
  • 3,873
  • 13
  • 33
  • 40
Mr. Royal
  • 21
  • 7

2 Answers2

0

In your $_POST handling, use the following:

$fullpath = $_FILES["Name_Of_The_Input_Field_For_The_File"]["tmp_name"];

See Getting complete PATH of uploaded file - PHP for a similar issue.

Nick Duncan
  • 749
  • 5
  • 17
0

Instead of doing a double POST, you can do something like this:

function readURL(input) {

  if (input.files && input.files[0]) {
    var reader = new FileReader();

    reader.onload = function(e) {
      $('#blah').attr('src', e.target.result);
    }

    reader.readAsDataURL(input.files[0]);
  }
}

$("#imgInp").change(function() {
  readURL(this);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form id="form1" runat="server">
  <input type='file' id="imgInp" />
  <img id="blah" src="#" alt="your image" />
</form>

Remember, that just because you've selected a file to upload doesn't mean its been uploaded. The server still hasn't received the data, thus, doing this on the client side makes a little more sense from what i gather you want to do.

(stolen from: Preview an image before it is uploaded)

Javier Buzzi
  • 4,313
  • 28
  • 40