Recently, when I was working on a small project, I used JavaScript to preview local images, but I did not display any debugging in IE.
Use IE's developer tool (F12) to debug and monitor Javascript. Path = C:/fakepath/chrysanthemum.jpg
After the document. getelementbyid ("myimg"). src = path is executed, the obtained path is file: // C:/fakepath/chrysanthemum.jpg.
So I started to find a solution on the Internet. Now I will share the solution I found with you!
The reason is that the security option is added to IE8. By default, the actual path of the uploaded file is not displayed. Go to the Internet option and modify the settings to display the actual file path.
The operation is as follows: Tools-> Internet Options-> Security-> Custom Level-> Find "include local directory path when uploading local files to the server" in "others ", select "enable.
Of course, some people will say that you cannot ask your customers to make these settings, so you have to find other solutions.
1 <SCRIPT type = "text/JavaScript">
2 Function Getpath (OBJ ){
3 If (OBJ ){
4 If (Window. Navigator. useragent. indexof ("MSIE")> = 1 ){
5 OBJ. Select (); Return Document. selection. createRange (). text;
6 }
7 Else If (Window. Navigator. useragent. indexof ("Firefox")> = 1 ){
8 If (Obj. Files ){
9 Return OBJ. Files. Item (0). getasdataurl ();
10 }
11 Return OBJ. value;
12 }
13 Return OBJ. value;
14 }
15 }
16
17 // The complete client path is as follows:
18 VaR Filepath = getpath (document. getelementbyid ("iptfileupload "));
19 </SCRIPT>
The above method does not need to be modified by the customer. You can try it. The above is also the information I found online. I will share it with you for ease of use ~~