最近在測試使用一個jquery插件uploadify,最新版3.1
在網上找到一些資料,整理收藏一些.
onSelect : function(file) {}//這個方法就是當選擇了圖片了觸發的事件
onUploadComplete : function(file)
{}//這個方法是當圖片上傳完成後觸發的事件
$(function() {
$('#file_upload').uploadify({
swf : '/js/uploadify/uploadify.swf',
uploader : 'http://up.6v.com/blog/uploadAvatar',
buttonText :'修改頭像',
formData :{blogid:<?=$bloginfo ["Blogid"]?>},
onUploadSuccess : function(file, data, response) {
data=eval_r("("+data+")");
showcut( data);
}
});
});
這裏的formData是指同文件一起發送的數據,默認是post
因爲它用的是swfupload,所以是支持跨域的,在根目錄下建個crossdomain.xml文件
<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<allow-access-from domain="*.qweibo.com" />//此處是你支持跨的域名
</cross-domain-policy>
完成這些就差不多了,還得靠自己啊,網站有時太坑人了
onDialogClose :
function(swfuploadifyQueue) {//當文件選擇對話框關閉時觸發
if( swfuploadifyQueue.filesErrored > 0
){
alert( '添加至隊列時有'
+swfuploadifyQueue.filesErrored
+'個文件發生錯誤n'
+'錯誤信息:'
+swfuploadifyQueue.errorMsg
+'n選定的文件數:'
+swfuploadifyQueue.filesSelected
+'n成功添加至隊列的文件數:'
+swfuploadifyQueue.filesQueued
+'n隊列中的總文件數量:'
+swfuploadifyQueue.queueLength);
}
}
onDialogOpen :
function() {//當選擇文件對話框打開時觸發
alert( 'Open!');
}
onSelect :
function(file) {//當每個文件添加至隊列後觸發
alert( 'id: ' + file.id
+ ' - 索引: ' + file.index
+ ' - 文件名: ' + file.name
+ ' - 文件大小: ' + file.size
+ ' - 類型: ' + file.type
+ ' - 創建日期: ' + file.creationdate
+ ' - 修改日期: ' + file.modificationdate
+ ' - 文件狀態: ' + file.filestatus);
}
onSelectError :
function(file,errorCode,errorMsg) {//當文件選定發生錯誤時觸發
alert( 'id: ' + file.id
+ ' - 索引: ' + file.index
+ ' - 文件名: ' + file.name
+ ' - 文件大小: ' + file.size
+ ' - 類型: ' + file.type
+ ' - 創建日期: ' + file.creationdate
+ ' - 修改日期: ' + file.modificationdate
+ ' - 文件狀態: ' + file.filestatus
+ ' - 錯誤代碼: ' + errorCode
+ ' - 錯誤信息: ' + errorMsg);
}
onQueueComplete :
function(stats) {//當隊列中的所有文件全部完成上傳時觸發
alert( '成功上傳的文件數: ' + stats.successful_uploads
+ ' - 上傳出錯的文件數: ' + stats.upload_errors
+ ' - 取消上傳的文件數: ' + stats.upload_cancelled
+ ' - 出錯的文件數' + stats.queue_errors);
}
onUploadComplete :
function(file,swfuploadifyQueue) {//隊列中的每個文件上傳完成時觸發一次
alert( 'id: ' + file.id
+ ' - 索引: ' + file.index
+ ' - 文件名: ' + file.name
+ ' - 文件大小: ' + file.size
+ ' - 類型: ' + file.type
+ ' - 創建日期: ' + file.creationdate
+ ' - 修改日期: ' + file.modificationdate
+ ' - 文件狀態: ' + file.filestatus
+ ' - 出錯的文件數: ' + swfuploadifyQueue.filesErrored
+ ' - 錯誤信息: ' + swfuploadifyQueue.errorMsg
+ ' - 要添加至隊列的數量: ' + swfuploadifyQueue.filesSelected
+ ' - 添加至對立的數量: ' + swfuploadifyQueue.filesQueued
+ ' - 隊列長度: ' + swfuploadifyQueue.queueLength);
}
onUploadError :
function(file,errorCode,errorMsg,errorString,swfuploadifyQueue)
{//上傳文件出錯是觸發(每個出錯文件觸發一次)
alert( 'id: ' + file.id
+ ' - 索引: ' + file.index
+ ' - 文件名: ' + file.name
+ ' - 文件大小: ' + file.size
+ ' - 類型: ' + file.type
+ ' - 創建日期: ' + file.creationdate
+ ' - 修改日期: ' + file.modificationdate
+ ' - 文件狀態: ' + file.filestatus
+ ' - 錯誤代碼: ' + errorCode
+ ' - 錯誤描述: ' + errorMsg
+ ' - 簡要錯誤描述: ' + errorString
+ ' - 出錯的文件數: ' + swfuploadifyQueue.filesErrored
+ ' - 錯誤信息: ' + swfuploadifyQueue.errorMsg
+ ' - 要添加至隊列的數量: ' + swfuploadifyQueue.filesSelected
+ ' - 添加至對立的數量: ' + swfuploadifyQueue.filesQueued
+ ' - 隊列長度: ' + swfuploadifyQueue.queueLength);
}
onUploadProgress :
function(file,fileBytesLoaded,fileTotalBytes,
queueBytesLoaded,swfuploadifyQueueUploadSize) {//上傳進度發生變更時觸發
alert( 'id: ' + file.id
+ ' - 索引: ' + file.index
+ ' - 文件名: ' + file.name
+ ' - 文件大小: ' + file.size
+ ' - 類型: ' + file.type
+ ' - 創建日期: ' + file.creationdate
+ ' - 修改日期: ' + file.modificationdate
+ ' - 文件狀態: ' + file.filestatus
+ ' - 當前文件已上傳: ' + fileBytesLoaded
+ ' - 當前文件大小: ' + fileTotalBytes
+ ' - 隊列已上傳: ' + queueBytesLoaded
+ ' - 隊列大小: ' + swfuploadifyQueueUploadSize);
}
onUploadStart:
function(file) {//上傳開始時觸發(每個文件觸發一次)
alert( 'id: ' + file.id
+ ' - 索引: ' + file.index
+ ' - 文件名: ' + file.name
+ ' - 文件大小: ' + file.size
+ ' - 類型: ' + file.type
+ ' - 創建日期: ' + file.creationdate
+ ' - 修改日期: ' + file.modificationdate
+ ' - 文件狀態: ' + file.filestatus );
}
onUploadSuccess :
function(file,data,response) {//上傳完成時觸發(每個文件觸發一次)
alert( 'id: ' + file.id
+ ' - 索引: ' + file.index
+ ' - 文件名: ' + file.name
+ ' - 文件大小: ' + file.size
+ ' - 類型: ' + file.type
+ ' - 創建日期: ' + file.creationdate
+ ' - 修改日期: ' + file.modificationdate
+ ' - 文件狀態: ' + file.filestatus
+ ' - 服務器端消息: ' + data
+ ' - 是否上傳成功: ' + response);
}