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 ??

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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

by Ivan--thanks Ivan

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.