How to get file size from clients without using activex in javascript?

Is there any other way to get client-side file size without using ActiveX in IE ?

I get the file size on the client side, but IE opens a security notification popup for ActiveX controls. Is there any other way to get the file size or hide the ActiveX popup?

Here is the code to get the file size on the client side.

 <html> <body> <form id="file"> <input type="file" id="loadfile" /> <input type="button" value="Image Size" onclick="testSize()" /> </form> <script type="text/javascript"> function testSize(){ var browserInfo = navigator.userAgent.toLowerCase(); if(browserInfo.indexOf("msie") > -1){ /* IE */ var filepath = document.getElementById('loadfile').value; alert(filepath + " Test "); var myFSO = new ActiveXObject("Scripting.FileSystemObject"); var thefile = myFSO.getFile(filepath); var imgbytes = thefile.size; alert( "name " + thefile.name + "Size " + thefile.size ); }else{ /* Other */ var file = document.getElementById('loadfile').files[0]; alert( "name " + file.name + "Size " + file.size ); } } </script> </body> </html> 

Thanks in advance.

+6
source share
1 answer

I got a solution.

There is no problem with geniune with code related to Internet Explorer browser security settings. Typically, you encounter this type of error when you want to open a text file or some excel files on a remote server.

go to internetoptions <security <customlevel <initialize and script active controls x are not marked as script-safe and marked by them, and I think your problem will be removed

thanks.

+3
source

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


All Articles