1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
| <!DOCTYPE html> <html>
<head> <meta charset="utf-8"> <title>Web Uploader</title> <link href="/lib/webuploader.css" rel="stylesheet" media="screen"> <script src="/lib/jquery.js" charset="utf-8"></script> <script src="/lib/webuploader.js" charset="utf-8"></script>
<style media="screen"> body { font-family: "微软雅黑", "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial, sans-serif; margin: 50px; }
#drop-area { color: gray; background: rgb(250,250,250); border: dashed 3px lightgray; width: 150px; height: 150px; padding: 20px; margin-bottom: 20px; line-height: 150px; text-align: center; } </style> </head>
<body> <div id="drop-area">拖拽图片到这里上传</div> <div id="uploader-demo"> <div id="filePicker">点击选择图片</div> <div id="fileList" class="uploader-list"></div> </div>
<script type="text/javascript"> if (!WebUploader.Uploader.support()) { alert( 'Web Uploader 不支持您的浏览器!如果你使用的是 IE 浏览器,请尝试升级 Flash 播放器'); throw new Error( 'WebUploader does not support the browser you are using.' ); }
var uploader = WebUploader.create({ auto: true, dnd: '#drop-area', swf: '/lib/Uploader.swf', server: '/webuploader', pick: '#filePicker', resize: false, accept: { title: 'Images', extensions: 'gif,jpg,jpeg,bmp,png', mimeTypes: 'image/*' }, compress: { width: 300, height: 300, allowMagnify: false, crop: false } });
uploader.onUploadSuccess = function(file, response) { console.log(response); uploader.removeFile(file, true); };
uploader.onUploadError = function(file, response) { console.log(response); };
uploader.onUploadProgress = function(file, percentage) { console.log(percentage); console.log('uploadProgress:' + file.id); };
uploader.onFileQueued = function(file) { console.log('fileQueued:' + file.id);
var $li = $( '<div id="' + file.id + '" class="file-item thumbnail">' + '<img>' + '<div class="info">' + file.name + '</div>' + '</div>' ); var $img = $li.find('img'); $('#fileList').append($li);
uploader.makeThumb(file, function(error, src) { if (error) { $img.replaceWith('<span>不能预览</span>'); return; }
$img.attr('src', src); }, 100, 100); }; </script> </body>
</html>
|