jQuery FileUpload 文件上传


jQuery File Upload 是一个Jquery图片上传组件,支持多文件上传、取消、删除,上传前缩略图预览、列表显示图片大小,支持上传进度条显示;支持各种动态语言开发的服务器端。

在线实例

实例预览 jQuery FileUpload简单实例DEMO

实例中用到的PHP上传类UploaderDemo.php点击下载

引入文件

  1. <script type="text/javascript" src="jquery.min.js"></script>
  2. <script type="text/javascript" src="jquery.ui.widget.js"></script>
  3. <script type="text/javascript" src="jquery.fileupload.js"></script>

使用方法

  1. <input type="file" value="" name="simplefile" id="simplefile" />
  1. <script>
  2. $('#simplefile').fileupload({
  3. url: "/static/php/UploaderDemo.php",
  4. dataType: 'json',
  5. done: function(e, JsonData) {
  6. var json = JsonData.result;
  7. if (json.state == 'success') {
  8. $imgHtml = '<span>';
  9. $imgHtml += '<a href="' + json.file + '" target="_blank">';
  10. $imgHtml += '<img src="' + json.file + '" width="100" height="100"  align="absmiddle"/>';
  11. $imgHtml += '</a>';
  12. $imgHtml += '<a href="javascript:uploadifyRemove(&quot;' + json.file + '&quot;)">删除</a>';
  13. $imgHtml += '</span>';
  14. $('#slide_preview').html($imgHtml)
  15. } else {
  16. alert(json.message)
  17. }
  18. return false
  19. }
  20. });
  21. function uploadifyRemove(filePath) {
  22. if (confirm('确定要删除吗?')) {
  23. $.post("/static/php/UploaderDemo.php?action=del", {
  24. filePath: filePath
  25. },
  26. function(res) {
  27. $('a[href="' + res + '"]').parent().remove()
  28. })
  29. }
  30. }
  31. </script>

下载地址