2

i am building one module wherein user can post their data. i have few text field and one image which while uploading via the HTML input control needs to previewed.

My Approach:

the HTML part:

    <div class="divClass" id="FirstAd">
<h4 align="center">
        Advertisement 1</h4>
    <div style="float: left; width:25%">
        <img src="images.jpg" id="replaceMe" width="100px" height="130px" /></div>
    <div style="float: right; width:70%; left:30%">
        <input type="text" style="width: 197px" /><br />
        <br />
        <textarea class="AdContent"></textarea><br />
        <br />
        <input type="file" id="myImage" size="30" onchange="pictureUpload()" /><br />
        <input type="button" value="Preview!"/><br/>
    </div>
</div>

the j Query part:

      function pictureUpload() {
        $(document).ready(function() {
            var imagepath = "file:\\" + $("#myImage").val();
            $("#replaceMe").attr("src", imagepath);
            alert(imagepath);
        });
    }

Am able to just get the filename with the extension not the path.

is there any alternative?? or some jquery plugin?? or can we retrieve the path inside a hidden field, since it is a security measure to prevent retrieving path from the file input ??

abhijit
  • 1,918
  • 3
  • 27
  • 38

2 Answers2

4

You can't do this. The input type="file" has security around it so that you can't directly access the file from JavaScript.

Daniel A. White
  • 174,715
  • 42
  • 343
  • 413
0

it can be done by this way there is post in stack overflow by

by Ivan--thanks Ivan

Community
  • 1
  • 1
abhijit
  • 1,918
  • 3
  • 27
  • 38