1

Hi guys I am creating a admin website for editing some products but whenever i edit a product I need to input some image again to the input file since I don't know how to set up the value to input file automatically.

Is there any way I can put the image to input file without the user choosing again the image just for the input file to be filled up.

<img src="foo-image" id="image">
<input type="file" name="image" id="imageFile">


<script type="text/javascript">    
    $(document).ready(function()
    {
        var src = $('#image').attr('src');
        $('#imageFile').val(src);

    });
</script>

The val does not work in the input file right? Is there any other way that the input file can be filled with data automatically? and so the security will not be jeopardize.

Pankaj Makwana
  • 3,030
  • 6
  • 31
  • 47
unknown
  • 397
  • 5
  • 20
  • 4
    it is not possible to set file in input type file – guradio Jul 18 '17 at 07:53
  • You should validate on server side. if file is chosen then upload file and update it to database otherwise don't upload and update it to database – Pankaj Makwana Jul 18 '17 at 07:55
  • 1
    @unknown This might help you https://stackoverflow.com/questions/1696877/how-to-set-a-value-to-a-file-input-in-html – Shiladitya Jul 18 '17 at 08:01
  • 2
    I can't figure out what you're trying to do here. The `src` of an image is a file on the server. But `` refers to a file on the client. But as @guradio said, you can't pre-fill a file input, the user has to select the file for security. – Barmar Jul 18 '17 at 08:05
  • u need to use custom input file where it shows the name of the file ... – Nadeemmnn Mohd Jul 18 '17 at 08:37

0 Answers0