webuploader的簡單使用javascript
須要的文件 自備 百度不少php
webuploader.js uploader.swf jQuery
css
-
-
-
-
-
-
<script type="text/javascript" src="jquery-1.10.2.min.js">
</script>
-
<script type="text/javascript" src="webuploader.js">
</script>
-
-
-
-
-
.webuploader-element-invisible {
-
position: absolute
!important;
-
clip:
rect(1px 1px 1px 1px);
/* IE6, IE7 */
-
clip:
rect(1px,1px,1px,1px);
-
-
-
-
-
-
-
-
-
-
-
-
-
.webuploader-pick-hover {
-
-
-
-
.webuploader-pick-disable {
-
-
-
-
-
-
-
<div id="uploader" class="wu-example">
-
-
<div id="thelist" class="uploader-list">
</div>
-
-
<div id="picker">選擇文件
</div>
-
<button id="ctlBtn" class="btn btn-default">開始上傳
</button>
-
-
-
<div id="fileList">
</div>
-
-
-
-
-
-
uploader = WebUploader.create({
-
resize:
false,
// 不壓縮image
-
swf:
'uploader.swf',
// swf文件路徑
-
server:
'upload.php',
// 文件接收服務端。
-
pick:
'#picker',
// 選擇文件的按鈕。可選。內部根據當前運行是建立,多是input元素,也多是flash.
-
-
chunkSize:
2*
1024*
1024,
//每一個分片大小
-
-
-
fileNumLimit:
20,
//上傳文件個數限制
-
fileSingleSizeLimit:
20*
1024*
1024,
//單個文件大小限制 20M
-
-
-
extensions:
'png,3gp,mp4,rmvb,mov,avi,m4v,wmv',
//上傳文件後綴
-
mimeTypes:
'image/*,video/*,audio/*,application/*'
//上傳文件類型
-
-
-
uploader.on(
'uploadStart',
function (file) {
-
-
-
$(
"#ctlBtn").click(
function () {
-
-
// uploader.upload();//這是將參數配置auto設置 false 手動上傳
-
-
uploader.on(
'fileQueued',
function( file ) {
//文件加入隊列後觸發
-
var $list = $(
"#fileList"),
-
-
'<div id="' + file.id +
'" class="file-item thumbnail">' +
'<img>'+
'<div class="info">' + file.name +
'</div>' +
'</div>'
-
-
-
-
-
-
uploader.makeThumb( file,
function( error, src ) {
//src base_64位
-
-
$img.replaceWith(
'<span>不能預覽</span>');
-
-
-
-
-
},
100,
100 );
//100x100爲縮略圖尺寸
-
-
-
uploader.on(
'uploadProgress',
function( file, percentage ) {
-
var ss=(percentage*
100)+
"%";
-
-
-
-
-
uploader.on(
'uploadSuccess',
function( file, res ) {
-
-
console.log(res.filePaht);
//這裏能夠獲得上傳後的文件路徑
-
-
-