开发者

How to read a client-side file header from a webpage?

I am making an online tool for identifying certain file types. I need to access some byte values from the file header to do this.

The user selects the file on the client machine. Somehow, I need to get the key byte values from the file, and then these are looked up in a server side database to categorize the file.

How can I read bytes from a client-side file?

I know I could have the user upload the file to the server, but these files are very large, and I only need a few bytes, so it would be slow and wasteful to upload the whole file.

Could I somehow upload part of the file开发者_如何学运维? It seems it is difficult to cancel a html form upload and the file-part is not available after cancel. Is this correct?

Is it possible to read a file in javascript? I have googled this, but the answer is unclear. I have read that it is possible with a java applet, but only if the applet is signed.

Is there some other way?


You can use html5, but will need to fallback on flash or some other non-javascript method for older browsers.

http://www.html5rocks.com/en/tutorials/file/dndfiles/


So. as Said above you must use non-javascript methodds. But each of this methods has some minus. FLASH - bad work with proxy. Really bad. Of course you can use flash obly for get base64 code of file and give it to js. In this case this will be work greate. Java Applet - greate work but not many users have JVM or versions of JVM may not be sasme (but if you will use JDK1.4 or 1.5 thi is no problem). ActiveX - work only in IE and on Windows HTML5 File Api - not cross browsers solution. Will be work only on last browsers and not in all.

of course much better use server side - in php for example getmimetype and other functions.

But I can manually change headers of my file. For example i can add to php file headers from jpeg or png - and your script will be think that is image.

So this is bad solution : use headers. For check filetype maybe simple use mimetype of file of trust to user and generate icon through file extension

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜