1

I am using input tag with attribute type="file" in HTML. If I browse and select image and try to get path of file with $('file_upload').val() in script it returns path as "C:\fakepath\img_name"*

I need to get this path and set as default to input tag from JavaScript.

Please help me with this.

Script:

$(document).ready(function() {$('#imgUpload_edit').change(
        function(){if ($(this).val()) {alert($('#imgUpload_edit').val());} }); });

HTML:

<FORM id="frmImgUpload_edit" ENCTYPE="multipart/form-data" ACTION="" METHOD="POST">
    <label for="imgUpload_edit" id="bold-text_edit">Select an image for the Device Type:</label>
    <input type="file" id="imgUpload_edit" name="deviceTypeImage_edit" size="10000"/>
    <div id="imageEditDeviceType"></div>
</FORM>
1

2 Answers 2

3

Sorry, that can't be done. It's a security feature.

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

Comments

-1

Can you create an input element using jQuery instead setting the value attribute of the input to the val of the element you want to get it from?

jQuery('input').attr("value",$('#imgUpload_edit').val())

You can string additional .attr such as id, etc as needed.

4 Comments

That would still get the security filtered file path.
What if the path is "http://...." as opposed to a local workspace like "C:..."? Then it wouldn't be a security issue.
— I've never seen a file input that accepted an HTTP URI. The control is designed to upload files from the user's file system to the website.
sorry, misread original question... would be a security breach to do this.

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.