ZK customers use JS to read txt file content issues end

  Recently encountered a problem when writing a demand, users need to click a button to directly read the contents of a txt file on his computer disk D to display the page, because the project is now written ZK. ZK is just for me not to know it is, many are not very familiar with. at first I wanted to use io stream to read, then finished find all txt files in the D drive on the server so that each reading, so in the internet for a long time. many of them get the file on the server or folder is uploaded to the server and then read. read files by file content directly address very little, because this is not safe. At present I have only found a way, but only if the IE browser .

 

<?page title="new page title" contentType="text/html;charset=UTF-8"?>
<zk>
<window title="ZK中使用JS读取客户端txt文件内容问题" border="normal">

   <button label="点击获取txt内容" id="butt"/>
   
   <label id="filePath" value="D:\\test.txt" style="display:none"/>
   
   <separator/>
   
   <label id="info" style="color:red"/>
   
   <script><![CDATA[
     zk.afterMount(function(){
        jq("$butt").click(function(){            
           try{    
                var fs =new ActiveXObject("Scripting.FileSystemObject");                    var TS, S;              }                    Alert ( "incompatible browsers, the security level is too high, can not be read, use a browser to open IE!");                
          the catch} (E) { 



             str = var "";
              var ForReading = 1;
               // file path, this is hard-coded in the label
               var path = JQ ( "$ filePath") text ();. // here with .val () get less value, after all, not JSP
            // read the contents of the file.      
            fs.OpenTextFile = TS (path, ForReading, to true);    
           (! ts.AtEndOfStream) the while {  
               S = ts.ReadLine (); 
               STR + = S; 
           }  
           ts.Close ();
            . JQ ( "$ info") text ( STR);  
         });
     });
   ]]> </ Script>
   
</ window>
</ ZK>

Since ActiveX is IE's plug-flow, so this can only be used in the IE browser. If you find that IE browser did not come out, then you probably did not open ActiveX plug-related functions, you need the following settings in IE

Then came out, but this network will also indicate the presence of a security risk, no way, this operation is inherently unsafe behavior. Other browsers, now I only know that after reading the contents of the file the user must manually select the files, you can not find the file path directly to read files on the client computer. If you know who the god, oh I can share.

Guess you like

Origin www.cnblogs.com/mycan/p/11809933.html