问题
Are there ways where I can use jQuery to improve the performance of a file uploader? There's a system where I am trying to hack to make the uploading process better. I am just doing some frontend override as I don't have permission to their server files.
The current uploader looks something like this:
<ul>
<li> <input type="file"></li>
<li> <input type="file"></li>
<li> <input type="file"></li>
<li> <input type="file"></li>
<li> <input type="file"></li>
</ul>
The downside using this is, you need to select images on-by-one and only limits you to upload 5 items.
so what I did, I added multiple="multiple" attributes in one of the inputs to let me select multiple items.
<ul>
<li> <input type="file" multiple="multiple"></li>
<li> <input type="file"></li>
<li> <input type="file"></li>
<li> <input type="file"></li>
<li> <input type="file"></li>
</ul>
By doing so, I was able to upload more than 5 items (7-8 items). One problem that I encounter is it CANNOT handle large files in a long session of uploading.
It can only handle images that can just sum up to 2 MB in total. But once the images sum up to something like 2.5 MB, it will keep uploading until 100% but in the end will return an error.
Are there jQuery plugins worth checking that you seem would be helpful? I need my session to last until it successfully finish uploading. I can only use javascript to override the process, nothing more.
回答1:
It's not something you can change from client-side. Upload limit is set on the server then you have to change that threshold there (how depends on your Internet server, Apache? IIS?).
For example if you're using PHP you can set the upload_max_filesize property in PHP.ini to the value you need (10Mb, for example). You can do it in a per-site base with .htaccess file (just prepend php_ to the property name).
If you're using IIS with ASP.NET you can change MaxRequestLength in the httpRuntime section under System.Web configuration (set the value in bytes to what you need).
Whatever is the value you set you'll always have a limit then you should notify your client too when it's reached (IIS for example just abort the request). There are several way to achieve this, the one I found more easy is to put the uploader inside an iframe and to check periodically the readyState property of the document (you may need to write a little bit more code of what you expect to make it cross-browser).
来源:https://stackoverflow.com/questions/11590384/hacking-an-uploader-to-handle-large-files-using-jquery