where the user selects the image file. Is it possible to display this image on th...">

Show selected file without postback

I have <input type="file">where the user selects the image file. Is it possible to display this image on the page without first uploading it to the server? Basically, what I want to do is use a local file from a user machine.

PS - I am using jQuery.

+2
source share
5 answers

It is impossible, even if referencing a file with file://will not work, when you get the value from the file input field, you will only get the file name, not the path. Therefore, it is impossible to find out where the image is. To make it work, you will need to use a Flash-based bootloader.

, , , Internet Explorer , , c:\fakepath\filename.png. , , JavaScript - .

C:\test.txt:

  • Firefox 3.5.6
    test.txt

  • Chrome 3.0.195.38
    test.txt

  • Opera 10.00
    C:\fake_path\test.txt

  • Internet Explorer 8
    C:\fakepath\test.txt

+5

, . Javascript .

, , , " ". , javascript . , MS Word - , .

+3

Javascript. , .

+1

:-), , .

document.getElementByid('img1').src = document.getElementById('fileUpload').value;

0

Internet Explorer, " ", C:\fakepath\- , . .

- !

0
source

Source: https://habr.com/ru/post/1730839/


All Articles