Is there any way to find out the file size before uploading the file using AJAX / PHP in change event of input file?
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- Carriage Return (ASCII chr 13) is missing from tex
- How to fix IE ClearType + jQuery opacity problem i
- void before promise syntax
you need to do an ajax HEAD request to get the filesize. with jquery it's something like this
Please do not use
ActiveX
as chances are that it will display a scary warning message in Internet Explorer and scare your users away.If anyone wants to implement this check, they should only rely on the FileList object available in modern browsers and rely on server side checks only for older browsers (progressive enhancement).
For the HTML bellow
try the following:
See following thread:
How to check file input size with jQuery?
I had the same problem and seems like we haven't had an accurate solution. Hope this can help other people.
After take time exploring around, I finally found the answer. This is my code to get file attach with jQuery:
This is just the example code for getting the file size. If you want do other stuffs, feel free to change the code to satisfy your needs.
Work on IE and FF
Browsers with HTML5 support has files property for input type. This will of course not work in older IE versions.