日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Bootstrap FileInput(文件上传)中文API整理

發布時間:2023/12/10 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Bootstrap FileInput(文件上传)中文API整理 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

下載地址、API和DOM地址(英語好的小伙伴可以看看)

下載地址:https://github.com/kartik-v/bootstrap-fileinput
API文檔 :http://plugins.krajee.com/file-input
D E M O:http://plugins.krajee.com/file-input/demo


做項目用到bootstrap fileinput插件上傳文件,在用的過程中,遇到一些問題,所以想著整理一份比較詳細的文檔,方便自己今后使用,也希望能給大家帶來幫助,如有錯誤,希望大家積極指正,積極交流。
注意:第三部分內容因為存在i標簽,某些文字被轉換成圖標

一、引入文件

<link href="../css/bootstrap.min.css"rel="stylesheet">
<link href="../css/fileinput.css" media="all"rel="stylesheet" type="text/css" />
<scriptsrc="../js/jquery-2.0.3.min.js"></script>
<script src="../js/fileinput.js"type="text/javascript"></script>
<script src="../js/bootstrap.min.js"type="text/javascript"></script>

二、初始化設置

//初始化fileinput initFileInput(); function initFileInput() {$("#uploadImg").fileinput({language: 'zh', //設置語言dropZoneTitle: '可以將圖片拖放到這里 …支持多文件上傳',uploadUrl: "index.php", //上傳的地址uploadExtraData: function(previewId, index) { //該插件可以向您的服務器方法發送附加數據。這可以通過uploadExtraData在鍵值對中設置為關聯數組對象來完成。所以如果你有設置uploadExtraData={id:'kv-1'},在PHP中你可以讀取這些數據$_POST['id']var id = $('#id').val();return {seriesId: id};},allowedFileExtensions: ['jpg','png'],//接收的文件后綴uploadAsync: true, //默認異步上傳showUpload: true, //是否顯示上傳按鈕showRemove: true, //顯示移除按鈕showPreview: true, //是否顯示預覽showCancel:true, //是否顯示文件上傳取消按鈕。默認為true。只有在AJAX上傳過程中,才會啟用和顯示showCaption: true,//是否顯示文件標題,默認為truebrowseClass: "btn btn-primary", //文件選擇器/瀏覽按鈕的CSS類。默認為btn btn-primarydropZoneEnabled: true,//是否顯示拖拽區域minImageWidth: 50, //圖片的最小寬度minImageHeight: 50,//圖片的最小高度maxImageWidth: 1000,//圖片的最大寬度maxImageHeight: 1000,//圖片的最大高度maxFileSize: 1024,//單位為kb,如果為0表示不限制文件大小minFileCount: 1, //每次上傳允許的最少文件數。如果設置為0,則表示文件數是可選的。默認為0maxFileCount: 0, //每次上傳允許的最大文件數。如果設置為0,則表示允許的文件數是無限制的。默認為0previewFileIcon: "<i class='glyphicon glyphicon-king'></i>",//當檢測到用于預覽的不可讀文件類型時,將在每個預覽文件縮略圖中顯示的圖標。默認為<i class="glyphicon glyphicon-file"></i> layoutTemplates:{actionUpload:''//去除上傳預覽縮略圖中的上傳圖片actionZoom:'', //去除上傳預覽縮略圖中的查看詳情預覽的縮略圖標actionDownload:'' //去除上傳預覽縮略圖中的下載圖標actionDelete:'', //去除上傳預覽的縮略圖中的刪除圖標},//對象用于渲染布局的每個部分的模板配置。您可以設置以下模板來控制窗口小部件布局.eg:去除上傳圖標msgFilesTooMany: "選擇上傳的文件數量({n}) 超過允許的最大數值{m}!",//字符串,當文件數超過設置的最大計數時顯示的消息 maxFileCount。默認為:選擇上傳的文件數({n})超出了允許的最大限制{m}。請重試您的上傳!}).on('filebatchpreupload', function(event, data) { //該方法將在上傳之前觸發var id = $('#id option:selected').val();if(id == 0){return {message: "請選擇", // 驗證錯誤信息在上傳前要顯示。如果設置了這個設置,插件會在調用時自動中止上傳,并將其顯示為錯誤消息。您可以使用此屬性來讀取文件并執行自己的自定義驗證data:{} // any other data to send that can be referred in `filecustomerror`};}}); } //fileuploaded此事件僅針對ajax上傳觸發,并在每個縮略圖文件上傳完成后觸發。此事件僅針對ajax上傳并在以下情況下觸發:當點擊每個預覽縮略圖中的上傳圖標并且文件上傳成功時,或者當你有 uploadAsync設置為true您已觸發批量上傳。在這種情況下,fileuploaded每一個人選擇的文件被上傳成功后,觸發事件。 var id_str = ''; $('#uploadImg').on('fileuploaded', function(event, data, previewId, index) {if(typeof(data.response.id) != 'undefined'){id_str = id_str+data.response.id+',';} }); // filebatchuploadcomplete此事件僅在ajax上傳和完成同步或異步ajax批量上傳后觸發。 $('#uploadImg').on('filebatchuploadcomplete',function (event,files,extra) {if(id_str.length == 0){layer.msg('上傳失敗', {icon: 0});//彈框提示return false;}setTimeout(function(){ //執行延時關閉closeSelf();},1000); });

三、Options 說明

屬性名屬性類型描述說明默認值
languageString多語言設置,使用時需提前引入locales文件夾下對應的語言文件,中文zh,引入語言文件必須放在fileinput.js之后'en'
showCaptionBoolean是否顯示被選文件的簡介true
showBrowseBoolean是否顯示瀏覽按鈕true
showPreviewBoolean是否顯示預覽區域true
showRemoveBoolean是否顯示移除按鈕true,
showUploadBoolean是否顯示上傳按鈕true,
showCancelBoolean是否顯示取消按鈕true,
showClose:Boolean是否顯示關閉按鈕true
showUploadedThumbsBoolean?true
browseOnZoneClickBoolean?false
autoReplaceBoolean是否自動替換當前圖片,設置為true時,再次選擇文件, 會將當前的文件替換掉。false
generateFileIdObject?null
previewClassString添加預覽按鈕的類屬性‘’
captionClassString?‘’
frameClassString?'krajee-default'
mainClassString?'file-caption-main'
mainTemplateObject?null
purifyHtmlBoolean?true
fileSizeGetterObject?null
initialCaptionString?''
initialPreviewArray/Object?[]
initialPreviewDelimiterString?'$$'
initialPreviewAsDataBoolean?false
initialPreviewFileTypeString?'image'
initialPreviewConfigArray/Object?[]
initialPreviewThumbTagsArray/Object?[]
previewThumbTagsObject?{}
initialPreviewShowDeleteBoolean?true
removeFromPreviewOnErrorBoolean?false
deleteUrlString刪除圖片時的請求路徑''
deleteExtraDataObject刪除圖片時額外傳入的參數{}
overwriteInitialBoolean?true
previewZoomButtonIconsObject?{prev: '',next: '',toggleheader: '',fullscreen: '',borderless: '',close: ''},
previewZoomButtonClassesObject?{prev: 'btn btn-navigate',next: 'btn btn-navigate',toggleheader: 'btn btn-default btn-header-toggle',fullscreen: 'btn btn-default',borderless: 'btn btn-default',close: 'btn btn-default'},
preferIconicPreviewBoolrean?false
preferIconicZoomPreviewBoolrean?false
allowedPreviewTypesundefined?undefined
allowedPreviewMimeTypesObject?null
allowedFileTypesObject接收的文件后綴,如['jpg', 'gif', 'png'],不填將不限制上傳文件后綴類型null
allowedFileExtensionsObject?null
defaultPreviewContentObject?null
customLayoutTagsObject?{}
customPreviewTagsObject?{}
previewFileIconString?''
previewFileIconClassString?'file-other-icon'
previewFileIconSettingsObject?{}
previewFileExtSettingsObject?{}
buttonLabelClassString?'hidden-xs'
browseIconString?'?'
browseClassString?'btn btn-primary'
removeIconString?''
removeClassString?'btn btn-default'
cancelIconString?''
cancelClassString?'btn btn-default'
uploadIconString?''
uploadClassString?'btn btn-default'
uploadUrlString上傳文件路徑null
uploadAsyncboolean是否為異步上傳true
uploadExtraData?上傳文件時額外傳遞的參數設置{}
zoomModalHeightnumber?480
minImageWidthString圖片的最小寬度null
minImageHeightString圖片的最小高度null
maxImageWidthString圖片的最大寬度null
maxImageHeightString圖片的最大高度null
resizeImageboolean?false
resizePreferenceString?'width'
resizeQualitynumber?0.92
resizeDefaultImageTypeString?'image/jpeg'
minFileSizenumber單位為kb,上傳文件的最小大小值0
maxFileSizenumber單位為kb,如果為0表示不限制文件大小0
resizeDefaultImageTypenumber?25600(25MB)
minFileCountnumber表示同時最小上傳的文件個數0
maxFileCountnumber表示允許同時上傳的最大文件個數0
validateInitialCountboolean?false
msgValidationErrorClassString?'text-danger'
msgValidationErrorIconString?' '
msgErrorClassString?'file-error-message'
progressThumbClassString?"progress-bar progress-bar-success progress-bar-striped active"
rogressClassString?"progress-bar progress-bar-success progress-bar-striped active"
progressCompleteClassString?"progress-bar progress-bar-success"
progressErrorClassString?"progress-bar progress-bar-danger"
progressUploadThresholdnumber?99
previewFileTypeString預覽文件類型,內置['image', 'html', 'text', 'video', 'audio', 'flash', 'object',‘other‘]等格式'image'
elCaptionContainerString?null
elCaptionTextString設置標題欄提示信息null
elPreviewContainerString?null
elPreviewImageString?null
elPreviewStatusString?null
elErrorContainerString?null
errorCloseButtonString?'<span class="close kv-error-close">×</span>'
slugCallbackfunction選擇后未上傳前 回調方法null
dropZoneEnabledboolean是否顯示拖拽區域true
dropZoneTitleClassString拖拽區域類屬性設置'file-drop-zone-title'
fileActionSettingsObject設置預覽圖片的顯示樣式{showRemove: true,showUpload: false,showZoom: true,showDrag: true,removeIcon: '',removeClass: 'btn btn-xs btn-default',removeTitle: 'Remove file',uploadIcon: '',uploadClass: 'btn btn-xs btn-default',uploadTitle: 'Upload file',zoomIcon: '',zoomClass: 'btn btn-xs btn-default',zoomTitle: 'View Details',dragIcon: '',dragClass: 'text-info',dragTitle: 'Move / Rearrange',dragSettings: {},indicatorNew: '',indicatorSuccess: '',indicatorError: '',indicatorLoading: '',indicatorNewTitle: 'Not uploaded yet',indicatorSuccessTitle: 'Uploaded',indicatorErrorTitle: 'Upload Error',indicatorLoadingTitle: 'Uploading ...'}
otherActionButtonsString?''
textEncodingString編碼設置'UTF-8'
ajaxSettingsObject?{}
ajaxDeleteSettingsObject?{}
showAjaxErrorDetailsboolean?true

四、提示說明設置

屬性名默認值中文
fileSinglefile文件
filePluralfiles個文件
browseLabelBrowse &hellip選擇 …
removeLabelRemove移除
removeTitleClear selected files清除選中文件
cancelLabelCancel取消
cancelTitleAbort ongoing upload取消進行中的上傳
uploadLabelUpload上傳
uploadTitleUpload selected files上傳選中文件
msgNoNo沒有
msgNoFilesSelectedNo files selected“”
msgCancelledCancelled取消
msgZoomModalHeadingDetailed Preview詳細預覽
msgSizeTooSmallFile "{name}" ({size} KB) is too small and must be larger than {minSize} KB.File "{name}" ({size} KB) is too small and must be larger than {minSize} KB.
msgSizeTooLargeFile "{name}" ({size} KB) exceeds maximum allowed upload size of {maxSize} KB.文件 "{name}" ({size} KB) 超過了允許大小 {maxSize} KB.
msgFilesTooLessYou must select at least {n} {files} to upload.你必須選擇最少 {n} {files} 來上傳.
msgFilesTooManyNumber of files selected for upload ({n}) exceeds maximum allowed limit of {m}.選擇的上傳文件個數 ({n}) 超出最大文件的限制個數 {m}.
msgFileNotFoundFile "{name}" not found!文件 "{name}" 未找到!
msgFileSecuredSecurity restrictions prevent reading the file "{name}".安全限制,為了防止讀取文件 "{name}".
msgFileNotReadableFile "{name}" is not readable.文件 "{name}" 不可讀.
msgFilePreviewAbortedFile preview aborted for "{name}".取消 "{name}" 的預覽.
msgFilePreviewErrorAn error occurred while reading the file "{name}".讀取 "{name}" 時出現了一個錯誤.
msgInvalidFileNameInvalid or unsupported characters in file name "{name}".Invalid or unsupported characters in file name "{name}".
msgInvalidFileTypeInvalid type for file "{name}". Only "{types}" files are supported.不正確的類型 "{name}". 只支持 "{types}" 類型的文件.
msgInvalidFileExtensionInvalid extension for file "{name}". Only "{extensions}" files are supported.不正確的文件擴展名 "{name}". 只支持 "{extensions}" 的文件擴展名.
msgFileTypes{'image': 'image','html': 'HTML','text': 'text','video': 'video','audio': 'audio','flash': 'flash','pdf': 'PDF','object': 'object'},{'image': 'image','html': 'HTML','text': 'text','video': 'video','audio': 'audio','flash': 'flash','pdf': 'PDF','object': 'object'},
msgUploadAbortedThe file upload was aborted該文件上傳被中止
msgUploadThresholdProcessing...Processing...
msgUploadBeginInitializing...Initializing...
msgUploadEndDoneDone
msgUploadEmptyNo valid data available for upload.No valid data available for upload.
msgValidationErrorValidation Error驗證錯誤
msgLoadingLoading file {index} of {files} …加載第 {index} 文件 共 {files} …
msgProgressLoading file {index} of {files} - {name} - {percent}% completed.加載第 {index} 文件 共 {files} - {name} - {percent}% 完成.
msgSelected{n} {files} selected{n} {files} 選中
msgFoldersNotAllowedDrag & drop files only! {n} folder(s) dropped were skipped.只支持拖拽文件! 跳過 {n} 拖拽的文件夾.
msgImageWidthSmallWidth of image file "{name}" must be at least {size} px.寬度的圖像文件的"{name}"的必須是至少{size}像素.
msgImageHeightSmallHeight of image file "{name}" must be at least {size} px.圖像文件的"{name}"的高度必須至少為{size}像素.
msgImageWidthLargeWidth of image file "{name}" cannot exceed {size} px.寬度的圖像文件"{name}"不能超過{size}像素.
msgImageHeightLargeHeight of image file "{name}" cannot exceed {size} px.圖像文件"{name}"的高度不能超過{size}像素.
msgImageResizeErrorCould not get the image dimensions to resize.無法獲取的圖像尺寸調整。
msgImageResizeExceptionError while resizing the image.<pre>{errors}</pre>錯誤而調整圖像大小。<pre>{errors}</pre>
msgAjaxErrorSomething went wrong with the {operation} operation. Please try again later!Something went wrong with the {operation} operation. Please try again later!
msgAjaxProgressError{operation} failed{operation} failed
ajaxOperations{deleteThumb: 'file delete', uploadThumb: 'file upload', uploadBatch: 'batch file upload', uploadExtra: 'form data upload' },{deleteThumb: 'file delete',uploadThumb: 'file upload', uploadBatch: 'batch file upload',uploadExtra: 'form data upload'},
dropZoneTitleDrag & drop files here …拖拽文件到這里 …
支持多文件同時上傳
dropZoneClickTitle
(or click to select {files})

(或點擊{files}按鈕選擇文件)
previewZoomButtonTitles{prev: 'View previous file',next: 'View next file', toggleheader: 'Toggle header',fullscreen: 'Toggle full screen', borderless: 'Toggle borderless mode', close: 'Close detailed preview' }{ prev: '預覽上一個文件',next: '預覽下一個文件',toggleheader: '縮放', fullscreen: '全屏', borderless: '無邊界模式',close: '關閉當前預覽'}
fileActionSettings?{ removeTitle: '刪除文件',uploadTitle: '上傳文件',zoomTitle: '查看詳情',dragTitle: '移動 / 重置',indicatorNewTitle: '沒有上傳', indicatorSuccessTitle: '上傳',indicatorErrorTitle: '上傳錯誤', indicatorLoadingTitle: '上傳 ...'},

五、Method說明

方法名描述
fileerror異步上傳錯誤結果處理$('#uploadfile').on('fileerror', function(event, data, msg) {});
fileuploaded異步上傳成功結果處理$("#uploadfile").on("fileuploaded", function (event, data, previewId, index) {})
filebatchuploaderror批量上傳錯誤結果處理$('#uploadfile').on('filebatchuploaderror', function(event, data, msg) {});
filebatchuploadsuccess批量上傳成功結果處理$('#uploadfile').on('filepreupload', function(event, data, previewId, index) {});
filebatchselected選擇文件后處理事件$("#fileinput").on("filebatchselected", function(event, files) {});
upload文件上傳方法$("#fileinput").fileinput("upload");
fileuploaded上傳成功后處理方法$("#fileinput").on("fileuploaded", function(event, data, previewId, index) {});
filereset?
fileclear點擊瀏覽框右上角X 清空文件前響應事件$("#fileinput").on("fileclear",function(event, data, msg){});
filecleared點擊瀏覽框右上角X 清空文件后響應事件$("#fileinput").on("filecleared",function(event, data, msg){});
fileimageuploaded

在預覽框中圖片已經完全加載完畢后回調的事件

轉載地址:https://segmentfault.com/a/1190000018477200

總結

以上是生活随笔為你收集整理的Bootstrap FileInput(文件上传)中文API整理的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。