JavaScript basics
Use JavaScript to determine the file size of uploaded files or pictures
If you are accustomed to using PHP as the server-side programming language, you will always encounter situations where you need to judge the file size when making files and uploading. If you don’t judge the file size, there may be files that exceed the server limit. For safety, it is better to judge the file size before uploading files.
However, if you use PHP to determine the file size, it is actually a waste of host resources. Just imagine a problem. If a netizen uploads a 100GB image compression file and you use PHP to determine the file size, you must first waste bandwidth. Send the 100GB file to the server to make subsequent judgments. If it is judged that the file is too large, so it is not uploaded, the 100GB bandwidth will not be wasted, and the host will also spend a lot of time and resources processing the PHP judgment .
In fact, there is a very good solution, which is to use JavaScript to judge directly on the user end (browser). If the file is judged to be too large, it will tell the netizen that it cannot be uploaded. On the contrary, if it is judged that there is no problem, then start to let the netizen upload. To your host, this configuration with PHP+JavaScript is of course much better. I originally wanted to write an introduction about judging the file size of uploaded files or pictures with JavaScript, but I just happened to see this introduction and it was pretty good, and it was very detailed.
[JavaScript] Check the image file size before uploading
http://www.dotblogs.com.tw/cross/archive/2010/09/21/17840.aspx
The original JavaScript of the browser does not seem to support direct judgment of file size. So this example uses the techniques of JQuery .
Post a Comment
0 Comments