uploadfiy v3.0中按鈕可以輕易修改成中英文,而不至於想2.xx版本中,需要對中文進行編碼。
3.0中圓圓的按鈕,很漂亮。
但是,3.0中去掉了原來的onComplete函式,並且也去掉了從伺服器端返回的response
$("#bibtext_upload").uploadify({
swf :'images/uploadify.swf',
uploader :'callback/uploadify.php',
fileTypeDesc :'選擇檔案',
fileTypeExts :'*.bib',
formData :{'folder' : '/bibtext'},//自定義儲存路徑
auto : true,
buttonCursor : 'hand',
buttonText : 'BIBTEXT',
fileSizeLimit : '10MB',
height : 20,
width : 100,
multi : true,
hideButton : true,
wmode : 'transparent',
onUploadComplete:function(file) {
//alert( 'id: ' + file.id + ' - 索引: ' + file.index + ' - 檔名: ' + file.name + ' - 檔案大小: ' + file.size + ' - 型別: ' + file.type + ' - 建立日期: ' + file.creationdate + ' - 修改日期: ' + file.modificationdate + ' - 檔案狀態: ' + file.filestatus);
},
onUploadError :function(file,errorString){
alert( 'id: ' + file.id + ' - 索引: ' + file.index + ' - 檔名: ' + file.name + ' - 檔案大小: ' + file.size + ' - 型別: ' + file.type + ' - 建立日期: ' + file.creationdate + ' - 修改日期: ' + file.modificationdate + ' - 檔案狀態: ' + file.filestatus + ' - 錯誤程式碼: ' + errorCode + ' - 錯誤描述: ' + errorMsg + ' - 簡要錯誤描述: ' + errorString);
},
onUploadSuccess : function(file,data,response) {//上傳完成時觸發(每個檔案觸發一次)
alert('The file was saved to: ' + data);
//alert( 'id: ' + file.id + ' - 索引: ' + file.index + ' - 檔名: ' + file.name + ' - 檔案大小: ' + file.size + ' - 型別: ' + file.type + ' - 建立日期: ' + file.creationdate + ' - 修改日期: ' + file.modificationdate + ' - 檔案狀態: ' + file.filestatus + ' - 伺服器端訊息: ' + data + ' - 是否上傳成功: ' + response);
}
});
伺服器端:
<?php
//使用uuid進行重名檔案
if (!empty($_FILES)) {
$tempFile = $_FILES['Filedata']['tmp_name'];
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/';
$new_file_name = new_name( $_FILES['Filedata']['name']);
$targetFile = str_replace('//','/',$targetPath) . $new_file_name;
move_uploaded_file($tempFile,iconv("UTF-8","gb2312", $targetFile));
echo $targetFile;//返回檔案路徑
}
/*重新命名檔案*/
function new_name($filename){
$ext = pathinfo($filename);
$ext = $ext['extension'];
$name = basename($filename,$ext);
$name = gen_uuid().'.'.$ext;
return $name;
}
function gen_uuid() {
return sprintf( '%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
// 32 bits for "time_low"
mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ),
// 16 bits for "time_mid"
mt_rand( 0, 0xffff ),
// 16 bits for "time_hi_and_version",
// four most significant bits holds version number 4
mt_rand( 0, 0x0fff ) | 0x4000,
// 16 bits, 8 bits for "clk_seq_hi_res",
// 8 bits for "clk_seq_low",
// two most significant bits holds zero and one for variant DCE1.1
mt_rand( 0, 0x3fff ) | 0x8000,
// 48 bits for "node"
mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff )
);
}
?>