一.upload的下載使用
1.下載地址:http://www.uploadify.com
2.導入flash版本
<link rel="stylesheet" type="text/css" href="/Public/css/party/uploadify.css">
<script type="text/javascript" src="/Public/js/party/jquery.uploadify.js"></script>
3.初始化
html代碼
<input id = "file_upload" type = "file" name = "file_upload" >
js初始化代碼
$(function() {
$('#file_upload').uploadify({
'swf' : SCOPE.ajax_upload_swf,
'uploader' : SCOPE.ajax_upload_image_url,
'buttonText': '上傳圖片',
'fileTypeDesc': 'Image Files',
'fileObjName' : 'file',
//允許上傳的文件後綴
'fileTypeExts': '*.gif; *.jpg; *.png',
'onUploadSuccess' : function(file,data,response) {
// response true ,false
if(response) {
var obj = JSON.parse(data); //由JSON字符串轉換爲JSON對象
console.log(data);
$('#' + file.id).find('.data').html(' 上傳完畢');
$("#upload_org_code_img").attr("src",obj.data);
$("#file_upload_image").attr('value',obj.data);
$("#upload_org_code_img").show();
}else{
alert('上傳失敗');
}
},
});
});
二.遇到問題
這時我們發現在谷歌瀏覽器文件上傳的樣式仍然是原來的樣式沒有變化
原因:flash控件被攔截了
解決辦法:設置->高級->內容設置->flash
進去以後把‘先詢問‘關閉即可
當我們刷新頁面後上傳按鈕便出來了