黑客使用jQuery上载上传器以处理大文件 [英] Hacking an uploader to handle large files using jQuery

查看:72
本文介绍了黑客使用jQuery上载上传器以处理大文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以使用jQuery来提高文件上传器的性能?我正在尝试破解一个系统,以改善上传过程.我只是在做一些前端覆盖,因为我没有访问它们的服务器文件的权限.

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>

使用此功能的缺点是,您需要一张一张地选择图片,并且只能上传5张图片.

The downside using this is, you need to select images on-by-one and only limits you to upload 5 items.

所以我做了什么,我在输入之一中添加了多个="multiple"属性,让我可以选择多个项目.

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>

这样做,我可以上传超过5个项目(7-8个项目).我遇到的一个问题是,它在长时间的上传过程中无法处理大文件.

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.

它只能处理总计不超过2 MB的图像.但是,一旦图像总计达到2.5 MB,它将继续上传直到100%,但最终将返回错误.

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.

是否有值得检查的jQuery插件对您有帮助?我需要我的会话持续到成功完成上传.我只能使用javascript覆盖该过程,仅此而已.

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.

推荐答案

这不是您可以从客户端更改的内容.在服务器上设置了上传限制,然后您必须在该服务器上更改该阈值(如何取决于Internet服务器Apache,IIS?).

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?).

例如,如果您使用的是PHP,则可以将PHP.ini中的upload_max_filesize属性设置为所需的值(例如10Mb).您可以使用.htaccess文件在每个站点中进行操作(只需在属性名称前添加php_即可).

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).

如果将IIS与ASP.NET一起使用,则可以在

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).

无论您设置的值是多少,都将始终有一个限制,然后在到达客户端时也应通知客户端(例如,IIS只是中止请求).有几种方法可以实现此目的,我发现更容易的一种方法是将上载器放在iframe中,并定期检查文档的readyState属性(您可能需要编写一些代码,期望使其跨浏览器.)

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).

这篇关于黑客使用jQuery上载上传器以处理大文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆