migrate to new git

This commit is contained in:
2025-08-29 01:27:25 +08:00
parent 946eb9961e
commit af2c152ef6
8623 changed files with 1000453 additions and 1 deletions

View File

@@ -0,0 +1,18 @@
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@@ -0,0 +1,296 @@
#[jQuery Upload File](http://hayageek.com/docs/jquery-upload-file.php)
##Overview
jQuery Upload File plugin provides Multiple file Uploads with progress bar.Works with any server-side platform (Google App Engine, PHP, Python, Ruby on Rails, Java, etc.) that supports standard HTML form file uploads.
---
#Demo
http://hayageek.com/docs/jquery-upload-file.php
---
#Supported Browsers
IE 8.0,IE 9.0,IE 10.0,Firefox,Safari,Opera,Chrome
Drag drop is supported in IE10,Firefox,Safari,Opera,Chrome
##API
###uploadFile( options )
Creates Ajax form and uploads the files to server.
````javascript
var uploadObj = $("#uploadDivId").uploadFile(options);
````
###startUpload()
uploads all the selected files. This function is used when <code>autoSubmit</code> option is set to <code>false</code>.
````javascript
uploadObj.startUpload();
````
###stopUpload()
Aborts all the uploads
````javascript
uploadObj.stopUpload();
````
###cancelAll()
Cancel all the selected files ( when autoSubmit:false)
````javascript
uploadObj.cancelAll();
````
#getResponses()
Responses from the server are collected and returned.
````javascript
uploadObj.getResponses()
````
---
##Options
###url
Server URL which handles File uploads
###method
Upload Form method type <code>POST</code> or <code>GET</code>. Default is <code>POST</code>
###enctype
Upload Form enctype. Default is <code>multipart/form-data</code>.
###formData
An object that should be send with file upload. <code>data: { key1: 'value1', key2: 'value2' }</code>
###dynamicFormData
To provide form data dynamically
````javascript
dynamicFormData: function()
{
//var data ="XYZ=1&ABCD=2";
var data ={"XYZ":1,"ABCD":2};
return data;
}
````
###maxFileSize
Allowed Maximum file Size in bytes.
###maxFileCount
Allowed Maximum number of files to be uploaded
###returnType
Expected data type of the response. One of: null, 'xml', 'script', or 'json'. The dataType option provides a means for specifying how the server response should be handled. This maps directly to jQuery's dataType method. The following values are supported:
* 'xml': server response is treated as XML and the 'success' callback method, if specified, will be passed the responseXML value
* 'json': server response will be evaluted and passed to the 'success' callback, if specified
* 'script': server response is evaluated in the global context
###allowedTypes
List of comma separated file extensions: Default is <code>"*"</code>. Example: <code>"jpg,png,gif"</code>
###acceptFiles
accept MIME type for file browse dialog. Default is <code>"*"</code>. Example: <code>"image/*"</code>
check this for full list : http://stackoverflow.com/questions/11832930/html-input-file-accept-attribute-file-type-csv
###fileName
Name of the file input field. Default is <code>file</code>
###multiple
If it is set to <code>true</code>, multiple file selection is allowed. Default is<code>false</code>
###dragDrop
Drag drop is enabled if it is set to <cod>true</code>
###autoSubmit
If it is set to <code>true</code>, files are uploaded automatically. Otherwise you need to call <code>.startUpload</code> function. Default is<code>true</code>
###showCancel
If it is set to <code>false</code>, Cancel button is hidden when <code>autoSubmit</code> is false. Default is<code>true</code>
###showAbort
If it is set to <code>false</code>, Abort button is hidden when the upload is in progress. Default is<code>true</code>
###showDone
If it is set to <code>false</code>, Done button is hidden when the upload is completed. Default is<code>true</code>
###showDelete
If it is set to <code>true</code>, Delete button is shown when the upload is completed. Default is<code>false</code>,You need to
implement deleteCallback() function.
###showDownload
If it is set to <code>true</code>, Download button is shown when the upload is completed. Default is<code>false</code>,You need to
implement downloadCallback() function.
###showStatusAfterSuccess
If it is set to <code>false</code>, status box will be hidden after the upload is done. Default is<code>true</code>
###showError
If it is set to <code>false</code>, Errors are not shown to user. Default is<code>true</code>
###showFileCounter
If it is set to <code>true</code>, File counter is shown with name. Default is<code>true</code>
File Counter style can be changed using <code>fileCounterStyle</code>. Default is <code>). </code>
###showProgress
If it is set to <code>true</code>, Progress precent is shown to user. Default is<code>false</code>
###showPreivew
If it is set to <code>true</code>, preview is shown to images. Default is<code>false</code>
###previewHeight
is used to set preview height. Default is : "auto"
###previewWidth
is used to set preview width. Default :"100%"
###showQueueDiv
Using this you can place the progressbar wherever you want.
````javascript
showQueueDiv: "output"
````
progress bar is added to a div with id <code>output</div>
###statusBarWidth
Using this you can set status bar width
###dragdropWidth
Using this you can set drag and drop div width
###update
update plugin options runtime.
````javascript
uploadObj.update({autoSubmit:true,maxFileCount:3,showDownload:false});
````
###onLoad
callback back to be invoked when the plugin is initialized. This can be used to show existing files..
````javascript
onLoad:function(obj)
{
$.ajax({
cache: false,
url: "load.php",
dataType: "json",
success: function(data)
{
for(var i=0;i<data.length;i++)
{
obj.createProgress(data[i]);
}
}
});
},
````
###onSelect
callback back to be invoked when the file selected.
````javascript
onSelect:function(files)
{
files[0].name;
files[0].size;
return true; //to allow file submission.
}
````
###onSubmit
callback back to be invoked before the file upload.
````javascript
onSubmit:function(files)
{
//files : List of files to be uploaded
//return flase; to stop upload
}
````
###onSuccess
callback to be invoked when the upload is successful.
````javascript
onSuccess:function(files,data,xhr,pd)
{
//files: list of files
//data: response from server
//xhr : jquer xhr object
}
````
###afterUploadAll
callback to be invoked when all the files are uploaded.
````javascript
afterUploadAll:function(obj)
{
//You can get data of the plugin using obj
}
````
###onError
callback to be invoked when the upload is failed.
````javascript
onError: function(files,status,errMsg,pd)
{
//files: list of files
//status: error status
//errMsg: error message
}
````
###onCancel
callback to be invoked when user cancel the file ( when autosubmit:false)
````javascript
onCancel: function(files,pd)
{
//files: list of files
//pd: progress div
}
````
###deleteCallback
callback to be invoked when the user clicks on Delete button.
````javascript
deleteCallback: function(data,pd)
{
for(var i=0;i<data.length;i++)
{
$.post("delete.php",{op:"delete",name:data[i]},
function(resp, textStatus, jqXHR)
{
//Show Message
alert("File Deleted");
});
}
pd.statusbar.hide(); //You choice to hide/not.
}
````
###downloadCallback
callback to be invoked when the user clicks on Download button.
````javascript
downloadCallback:function(files,pd)
{
location.href="download.php?filename="+files[0];
}
````
---
#Custom Errors
you can send custom errors from server. like "File exists".
for custom errors,expected json object from server is:
````javascript
{"jquery-upload-file-error":"File already exists"}
````

View File

@@ -0,0 +1,130 @@
.ajax-file-upload-statusbar {
border: 1px solid #0ba1b5;
margin-top: 10px;
margin-right: 10px;
margin: 5px;
-moz-border-radius: 4px;
-webkit-border-radius: 4px;
border-radius: 4px;
padding: 5px 5px 5px 5px
}
.ajax-file-upload-filename {
width: 100%;
height: auto;
margin: 0 5px 5px 10px;
color: #807579
}
.ajax-file-upload-progress {
margin: 0 10px 5px 10px;
position: relative;
width: 250px;
border: 1px solid #ddd;
padding: 1px;
border-radius: 3px;
display: inline-block
}
.ajax-file-upload-bar {
background-color: #0ba1b5;
width: 0;
height: 20px;
border-radius: 3px;
color:#FFFFFF;
}
.ajax-file-upload-percent {
position: absolute;
display: inline-block;
top: 3px;
left: 48%
}
.ajax-file-upload-red {
-moz-box-shadow: inset 0 39px 0 -24px #e67a73;
-webkit-box-shadow: inset 0 39px 0 -24px #e67a73;
box-shadow: inset 0 39px 0 -24px #e67a73;
background-color: #e4685d;
-moz-border-radius: 4px;
-webkit-border-radius: 4px;
border-radius: 4px;
display: inline-block;
color: #fff;
font-family: arial;
font-size: 13px;
font-weight: normal;
padding: 4px 15px;
text-decoration: none;
text-shadow: 0 1px 0 #b23e35;
cursor: pointer;
vertical-align: top;
margin-right:5px;
}
.ajax-file-upload-green {
background-color: #77b55a;
-moz-border-radius: 4px;
-webkit-border-radius: 4px;
border-radius: 4px;
margin: 0;
padding: 0;
display: inline-block;
color: #fff;
font-family: arial;
font-size: 13px;
font-weight: normal;
padding: 4px 15px;
text-decoration: none;
cursor: pointer;
text-shadow: 0 1px 0 #5b8a3c;
vertical-align: top;
margin-right:5px;
}
.ajax-file-upload {
font-family: Arial, Helvetica, sans-serif;
font-size: 16px;
font-weight: bold;
padding: 15px 20px;
cursor:pointer;
line-height:20px;
height:25px;
margin:0 10px 10px 0;
display: inline-block;
background: #fff;
border: 1px solid #e8e8e8;
color: #888;
text-decoration: none;
border-radius: 3px;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
-moz-box-shadow: 0 2px 0 0 #e8e8e8;
-webkit-box-shadow: 0 2px 0 0 #e8e8e8;
box-shadow: 0 2px 0 0 #e8e8e8;
padding: 6px 10px 4px 10px;
color: #fff;
background: #2f8ab9;
border: none;
-moz-box-shadow: 0 2px 0 0 #13648d;
-webkit-box-shadow: 0 2px 0 0 #13648d;
box-shadow: 0 2px 0 0 #13648d;
vertical-align:middle;
}
.ajax-file-upload:hover {
background: #3396c9;
-moz-box-shadow: 0 2px 0 0 #15719f;
-webkit-box-shadow: 0 2px 0 0 #15719f;
box-shadow: 0 2px 0 0 #15719f;
}
.ajax-upload-dragdrop
{
border:2px dotted #A5A5C7;
color: #DADCE3;
text-align:left;
vertical-align:middle;
padding:10px 10px 0px 10px;
}
.ajax-upload-dragdrop.state-hover
{
border: 2px solid #A5A5C7;
}
.ajax-file-upload-error {
color: red;
}

View File

@@ -0,0 +1,741 @@
/*!
* jQuery Upload File Plugin
* version: 3.1.10
* @requires jQuery v1.5 or later & form plugin
* Copyright (c) 2013 Ravishanker Kusuma
* http://hayageek.com/
*/
(function ($) {
if($.fn.ajaxForm == undefined) {
$.getScript(("https:" == document.location.protocol ? "https://" : "http://") + "malsup.github.io/jquery.form.js");
}
var feature = {};
feature.fileapi = $("<input type='file'/>").get(0).files !== undefined;
feature.formdata = window.FormData !== undefined;
$.fn.uploadFile = function (options) {
// This is the easiest way to have default options.
var s = $.extend({
// These are the defaults.
url: "",
method: "POST",
enctype: "multipart/form-data",
returnType: null,
allowDuplicates: true,
duplicateStrict: false,
allowedTypes: "*",
//For list of acceptFiles
// http://stackoverflow.com/questions/11832930/html-input-file-accept-attribute-file-type-csv
acceptFiles: "*",
fileName: "file",
formData: {},
dynamicFormData: function () {
return {};
},
maxFileSize: -1,
maxFileCount: -1,
multiple: true,
dragDrop: false,
autoSubmit: true,
showCancel: false,
showAbort: false,
showDone: false,
showDelete: false,
showError: false,
showStatusAfterSuccess: false,
showStatusAfterError: false,
showFileCounter: true,
fileCounterStyle: "). ",
showProgress: false,
nestedForms: true,
showDownload: false,
onLoad: function (obj) {},
onSelect: function (files) {
return true;
},
onSubmit: function (files, xhr) {},
onSuccess: function (files, response, xhr, pd) {},
onError: function (files, status, message, pd) {},
onCancel: function (files, pd) {},
downloadCallback: false,
deleteCallback: false,
afterUploadAll: false,
abortButtonClass: "ajax-file-upload-abort",
cancelButtonClass: "ajax-file-upload-cancel",
dragDropContainerClass: "ajax-upload-dragdrop",
dragDropHoverClass: "state-hover",
errorClass: "ajax-file-upload-error",
uploadButtonClass: "ajax-file-upload",
dragDropStr: "<span><b>Drag &amp; Drop Files</b></span>",
abortStr: "Abort",
cancelStr: "Cancel",
deletelStr: "Delete",
doneStr: "Done",
multiDragErrorStr: "Multiple File Drag &amp; Drop is not allowed.",
extErrorStr: "is not allowed. Allowed extensions: ",
duplicateErrorStr: "is not allowed. File already exists.",
sizeErrorStr: "is not allowed. Allowed Max size: ",
uploadErrorStr: "Upload is not allowed",
maxFileCountErrorStr: " is not allowed. Maximum allowed files are:",
downloadStr: "Download",
customErrorKeyStr: "jquery-upload-file-error",
showQueueDiv: false,
statusBarWidth: 500,
dragdropWidth: 500,
showPreview: false,
previewHeight: "auto",
previewWidth: "100%",
uploadFolder:""
}, options);
this.fileCounter = 1;
this.selectedFiles = 0;
this.fCounter = 0; //failed uploads
this.sCounter = 0; //success uploads
this.tCounter = 0; //total uploads
var formGroup = "ajax-file-upload-" + (new Date().getTime());
this.formGroup = formGroup;
this.hide();
this.errorLog = $("<div></div>"); //Writing errors
this.after(this.errorLog);
this.responses = [];
this.existingFileNames = [];
if(!feature.formdata) //check drag drop enabled.
{
s.dragDrop = false;
}
if(!feature.formdata) {
s.multiple = false;
}
var obj = this;
var uploadLabel = $('<div>' + $(this).html() + '</div>');
$(uploadLabel).addClass(s.uploadButtonClass);
// wait form ajax Form plugin and initialize
(function checkAjaxFormLoaded() {
if($.fn.ajaxForm) {
if(s.dragDrop) {
var dragDrop = $('<div class="' + s.dragDropContainerClass + '" style="vertical-align:top;"></div>').width(s.dragdropWidth);
$(obj).before(dragDrop);
$(dragDrop).append(uploadLabel);
$(dragDrop).append($(s.dragDropStr));
setDragDropHandlers(obj, s, dragDrop);
} else {
$(obj).before(uploadLabel);
}
s.onLoad.call(this, obj);
createCutomInputFile(obj, formGroup, s, uploadLabel);
} else window.setTimeout(checkAjaxFormLoaded, 10);
})();
this.startUpload = function () {
$("." + this.formGroup).each(function (i, items) {
if($(this).is('form')) $(this).submit();
});
}
this.getFileCount = function () {
return obj.selectedFiles;
}
this.stopUpload = function () {
$("." + s.abortButtonClass).each(function (i, items) {
if($(this).hasClass(obj.formGroup)) $(this).click();
});
}
this.cancelAll = function () {
$("." + s.cancelButtonClass).each(function (i, items) {
if($(this).hasClass(obj.formGroup)) $(this).click();
});
}
this.update = function (settings) {
//update new settings
s = $.extend(s, settings);
}
//This is for showing Old files to user.
this.createProgress = function (filename) {
var pd = new createProgressDiv(this, s);
pd.progressDiv.show();
pd.progressbar.width('100%');
var fileNameStr = "";
if(s.showFileCounter) fileNameStr = obj.fileCounter + s.fileCounterStyle + filename;
else fileNameStr = filename;
pd.filename.html(fileNameStr);
obj.fileCounter++;
obj.selectedFiles++;
if(s.showPreview)
{
pd.preview.attr('src',s.uploadFolder+filename);
pd.preview.show();
}
if(s.showDownload) {
pd.download.show();
pd.download.click(function () {
if(s.downloadCallback) s.downloadCallback.call(obj, [filename]);
});
}
pd.del.show();
pd.del.click(function () {
pd.statusbar.hide().remove();
var arr = [filename];
if(s.deleteCallback) s.deleteCallback.call(this, arr, pd);
obj.selectedFiles -= 1;
updateFileCounter(s, obj);
});
}
this.getResponses = function () {
return this.responses;
}
var checking = false;
function checkPendingUploads() {
if(s.afterUploadAll && !checking) {
checking = true;
(function checkPending() {
if(obj.sCounter != 0 && (obj.sCounter + obj.fCounter == obj.tCounter)) {
s.afterUploadAll(obj);
checking = false;
} else window.setTimeout(checkPending, 100);
})();
}
}
function setDragDropHandlers(obj, s, ddObj) {
ddObj.on('dragenter', function (e) {
e.stopPropagation();
e.preventDefault();
$(this).addClass(s.dragDropHoverClass);
});
ddObj.on('dragover', function (e) {
e.stopPropagation();
e.preventDefault();
var that = $(this);
if (that.hasClass(s.dragDropContainerClass) && !that.hasClass(s.dragDropHoverClass)) {
that.addClass(s.dragDropHoverClass);
}
});
ddObj.on('drop', function (e) {
e.preventDefault();
$(this).removeClass(s.dragDropHoverClass);
obj.errorLog.html("");
var files = e.originalEvent.dataTransfer.files;
if(!s.multiple && files.length > 1) {
if(s.showError) $("<div class='" + s.errorClass + "'>" + s.multiDragErrorStr + "</div>").appendTo(obj.errorLog);
return;
}
if(s.onSelect(files) == false) return;
serializeAndUploadFiles(s, obj, files);
});
ddObj.on('dragleave', function (e) {
$(this).removeClass(s.dragDropHoverClass);
});
$(document).on('dragenter', function (e) {
e.stopPropagation();
e.preventDefault();
});
$(document).on('dragover', function (e) {
e.stopPropagation();
e.preventDefault();
var that = $(this);
if (!that.hasClass(s.dragDropContainerClass)) {
that.removeClass(s.dragDropHoverClass);
}
});
$(document).on('drop', function (e) {
e.stopPropagation();
e.preventDefault();
$(this).removeClass(s.dragDropHoverClass);
});
}
function getSizeStr(size) {
var sizeStr = "";
var sizeKB = size / 1024;
if(parseInt(sizeKB) > 1024) {
var sizeMB = sizeKB / 1024;
sizeStr = sizeMB.toFixed(2) + " MB";
} else {
sizeStr = sizeKB.toFixed(2) + " KB";
}
return sizeStr;
}
function serializeData(extraData) {
var serialized = [];
if(jQuery.type(extraData) == "string") {
serialized = extraData.split('&');
} else {
serialized = $.param(extraData).split('&');
}
var len = serialized.length;
var result = [];
var i, part;
for(i = 0; i < len; i++) {
serialized[i] = serialized[i].replace(/\+/g, ' ');
part = serialized[i].split('=');
result.push([decodeURIComponent(part[0]), decodeURIComponent(part[1])]);
}
return result;
}
function serializeAndUploadFiles(s, obj, files) {
for(var i = 0; i < files.length; i++) {
if(!isFileTypeAllowed(obj, s, files[i].name)) {
if(s.showError) $("<div class='" + s.errorClass + "'><b>" + files[i].name + "</b> " + s.extErrorStr + s.allowedTypes + "</div>").appendTo(obj.errorLog);
continue;
}
if(!s.allowDuplicates && isFileDuplicate(obj, files[i].name)) {
if(s.showError) $("<div class='" + s.errorClass + "'><b>" + files[i].name + "</b> " + s.duplicateErrorStr + "</div>").appendTo(obj.errorLog);
continue;
}
if(s.maxFileSize != -1 && files[i].size > s.maxFileSize) {
if(s.showError) $("<div class='" + s.errorClass + "'><b>" + files[i].name + "</b> " + s.sizeErrorStr + getSizeStr(s.maxFileSize) + "</div>").appendTo(
obj.errorLog);
continue;
}
if(s.maxFileCount != -1 && obj.selectedFiles >= s.maxFileCount) {
if(s.showError) $("<div class='" + s.errorClass + "'><b>" + files[i].name + "</b> " + s.maxFileCountErrorStr + s.maxFileCount + "</div>").appendTo(
obj.errorLog);
continue;
}
obj.selectedFiles++;
obj.existingFileNames.push(files[i].name);
var ts = s;
var fd = new FormData();
var fileName = s.fileName.replace("[]", "");
fd.append(fileName, files[i]);
var extraData = s.formData;
if(extraData) {
var sData = serializeData(extraData);
for(var j = 0; j < sData.length; j++) {
if(sData[j]) {
fd.append(sData[j][0], sData[j][1]);
}
}
}
ts.fileData = fd;
var pd = new createProgressDiv(obj, s);
var fileNameStr = "";
if(s.showFileCounter) fileNameStr = obj.fileCounter + s.fileCounterStyle + files[i].name
else fileNameStr = files[i].name;
pd.filename.html(fileNameStr);
var form = $("<form style='display:block; position:absolute;left: 150px;' class='" + obj.formGroup + "' method='" + s.method + "' action='" +
s.url + "' enctype='" + s.enctype + "'></form>");
form.appendTo('body');
var fileArray = [];
fileArray.push(files[i].name);
ajaxFormSubmit(form, ts, pd, fileArray, obj, files[i]);
obj.fileCounter++;
}
}
function isFileTypeAllowed(obj, s, fileName) {
var fileExtensions = s.allowedTypes.toLowerCase().split(",");
var ext = fileName.split('.').pop().toLowerCase();
if(s.allowedTypes != "*" && jQuery.inArray(ext, fileExtensions) < 0) {
return false;
}
return true;
}
function isFileDuplicate(obj, filename) {
var duplicate = false;
if (obj.existingFileNames.length) {
for (var x=0; x<obj.existingFileNames.length; x++) {
if (obj.existingFileNames[x] == filename
|| s.duplicateStrict && obj.existingFileNames[x].toLowerCase() == filename.toLowerCase()
) {
duplicate = true;
}
}
}
return duplicate;
}
function removeExistingFileName(obj, fileArr) {
if (obj.existingFileNames.length) {
for (var x=0; x<fileArr.length; x++) {
var pos = obj.existingFileNames.indexOf(fileArr[x]);
if (pos != -1) {
obj.existingFileNames.splice(pos, 1);
}
}
}
}
function getSrcToPreview(file, obj) {
if(file) {
obj.show();
var reader = new FileReader();
reader.onload = function (e) {
obj.attr('src', e.target.result);
};
reader.readAsDataURL(file);
}
}
function updateFileCounter(s, obj) {
if(s.showFileCounter) {
var count = $(".ajax-file-upload-filename").length;
obj.fileCounter = count + 1;
$(".ajax-file-upload-filename").each(function (i, items) {
var arr = $(this).html().split(s.fileCounterStyle);
var fileNum = parseInt(arr[0]) - 1; //decrement;
var name = count + s.fileCounterStyle + arr[1];
$(this).html(name);
count--;
});
}
}
function createCutomInputFile(obj, group, s, uploadLabel) {
var fileUploadId = "ajax-upload-id-" + (new Date().getTime());
var form = $("<form method='" + s.method + "' action='" + s.url + "' enctype='" + s.enctype + "'></form>");
var fileInputStr = "<input type='file' id='" + fileUploadId + "' name='" + s.fileName + "' accept='" + s.acceptFiles + "'/>";
if(s.multiple) {
if(s.fileName.indexOf("[]") != s.fileName.length - 2) // if it does not endwith
{
s.fileName += "[]";
}
fileInputStr = "<input type='file' id='" + fileUploadId + "' name='" + s.fileName + "' accept='" + s.acceptFiles + "' multiple/>";
}
var fileInput = $(fileInputStr).appendTo(form);
fileInput.change(function () {
obj.errorLog.html("");
var fileExtensions = s.allowedTypes.toLowerCase().split(",");
var fileArray = [];
if(this.files) //support reading files
{
for(i = 0; i < this.files.length; i++) {
fileArray.push(this.files[i].name);
}
if(s.onSelect(this.files) == false) return;
} else {
var filenameStr = $(this).val();
var flist = [];
fileArray.push(filenameStr);
if(!isFileTypeAllowed(obj, s, filenameStr)) {
if(s.showError) $("<div class='" + s.errorClass + "'><b>" + filenameStr + "</b> " + s.extErrorStr + s.allowedTypes + "</div>").appendTo(
obj.errorLog);
return;
}
//fallback for browser without FileAPI
flist.push({
name: filenameStr,
size: 'NA'
});
if(s.onSelect(flist) == false) return;
}
updateFileCounter(s, obj);
uploadLabel.unbind("click");
form.hide();
createCutomInputFile(obj, group, s, uploadLabel);
form.addClass(group);
if(feature.fileapi && feature.formdata) //use HTML5 support and split file submission
{
form.removeClass(group); //Stop Submitting when.
var files = this.files;
serializeAndUploadFiles(s, obj, files);
} else {
var fileList = "";
for(var i = 0; i < fileArray.length; i++) {
if(s.showFileCounter) fileList += obj.fileCounter + s.fileCounterStyle + fileArray[i] + "<br>";
else fileList += fileArray[i] + "<br>";;
obj.fileCounter++;
}
if(s.maxFileCount != -1 && (obj.selectedFiles + fileArray.length) > s.maxFileCount) {
if(s.showError) $("<div class='" + s.errorClass + "'><b>" + fileList + "</b> " + s.maxFileCountErrorStr + s.maxFileCount + "</div>").appendTo(
obj.errorLog);
return;
}
obj.selectedFiles += fileArray.length;
var pd = new createProgressDiv(obj, s);
pd.filename.html(fileList);
ajaxFormSubmit(form, s, pd, fileArray, obj, null);
}
});
if(s.nestedForms) {
form.css({
'margin': 0,
'padding': 0
});
uploadLabel.css({
position: 'relative',
overflow: 'hidden',
cursor: 'default'
});
fileInput.css({
position: 'absolute',
'cursor': 'pointer',
'top': '0px',
'width': '100%',
'height': '100%',
'left': '0px',
'z-index': '100',
'opacity': '0.0',
'filter': 'alpha(opacity=0)',
'-ms-filter': "alpha(opacity=0)",
'-khtml-opacity': '0.0',
'-moz-opacity': '0.0'
});
form.appendTo(uploadLabel);
} else {
form.appendTo($('body'));
form.css({
margin: 0,
padding: 0,
display: 'block',
position: 'absolute',
left: '-250px'
});
if(navigator.appVersion.indexOf("MSIE ") != -1) //IE Browser
{
uploadLabel.attr('for', fileUploadId);
} else {
uploadLabel.click(function () {
fileInput.click();
});
}
}
}
function createProgressDiv(obj, s) {
this.statusbar = $("<div class='ajax-file-upload-statusbar'></div>").width(s.statusBarWidth);
this.preview = $("<img class='ajax-file-upload-preview' />").width(s.previewWidth).height(s.previewHeight).appendTo(this.statusbar).hide();
this.filename = $("<div class='ajax-file-upload-filename'></div>").appendTo(this.statusbar);
this.progressDiv = $("<div class='ajax-file-upload-progress'>").appendTo(this.statusbar).hide();
this.progressbar = $("<div class='ajax-file-upload-bar " + obj.formGroup + "'></div>").appendTo(this.progressDiv);
this.abort = $("<div class='ajax-file-upload-red " + s.abortButtonClass + " " + obj.formGroup + "'>" + s.abortStr + "</div>").appendTo(this.statusbar)
.hide();
this.cancel = $("<div class='ajax-file-upload-red " + s.cancelButtonClass + " " + obj.formGroup + "'>" + s.cancelStr + "</div>").appendTo(this.statusbar)
.hide();
this.done = $("<div class='ajax-file-upload-green'>" + s.doneStr + "</div>").appendTo(this.statusbar).hide();
this.download = $("<div class='ajax-file-upload-green'>" + s.downloadStr + "</div>").appendTo(this.statusbar).hide();
this.del = $("<div class='ajax-file-upload-red'>" + s.deletelStr + "</div>").appendTo(this.statusbar).hide();
if(s.showQueueDiv)
$("#" + s.showQueueDiv).append(this.statusbar);
else
obj.errorLog.after(this.statusbar);
return this;
}
function ajaxFormSubmit(form, s, pd, fileArray, obj, file) {
var currentXHR = null;
var options = {
cache: false,
contentType: false,
processData: false,
forceSync: false,
type: s.method,
data: s.formData,
formData: s.fileData,
dataType: s.returnType,
beforeSubmit: function (formData, $form, options) {
if(s.onSubmit.call(this, fileArray) != false) {
var dynData = s.dynamicFormData();
if(dynData) {
var sData = serializeData(dynData);
if(sData) {
for(var j = 0; j < sData.length; j++) {
if(sData[j]) {
if(s.fileData != undefined) options.formData.append(sData[j][0], sData[j][1]);
else options.data[sData[j][0]] = sData[j][1];
}
}
}
}
obj.tCounter += fileArray.length;
//window.setTimeout(checkPendingUploads, 1000); //not so critical
checkPendingUploads();
return true;
}
pd.statusbar.append("<div class='" + s.errorClass + "'>" + s.uploadErrorStr + "</div>");
pd.cancel.show()
form.remove();
pd.cancel.click(function () {
removeExistingFileName(obj, fileArray);
pd.statusbar.remove();
s.onCancel.call(obj, fileArray, pd);
obj.selectedFiles -= fileArray.length; //reduce selected File count
updateFileCounter(s, obj);
});
return false;
},
beforeSend: function (xhr, o) {
pd.progressDiv.show();
pd.cancel.hide();
pd.done.hide();
if(s.showAbort) {
pd.abort.show();
pd.abort.click(function () {
removeExistingFileName(obj, fileArray);
xhr.abort();
obj.selectedFiles -= fileArray.length; //reduce selected File count
});
}
if(!feature.formdata) //For iframe based push
{
pd.progressbar.width('5%');
} else pd.progressbar.width('1%'); //Fix for small files
},
uploadProgress: function (event, position, total, percentComplete) {
//Fix for smaller file uploads in MAC
if(percentComplete > 98) percentComplete = 98;
var percentVal = percentComplete + '%';
if(percentComplete > 1) pd.progressbar.width(percentVal)
if(s.showProgress) {
pd.progressbar.html(percentVal);
pd.progressbar.css('text-align', 'center');
}
},
success: function (data, message, xhr) {
//For custom errors.
if(s.returnType == "json" && $.type(data) == "object" && data.hasOwnProperty(s.customErrorKeyStr)) {
pd.abort.hide();
var msg = data[s.customErrorKeyStr];
s.onError.call(this, fileArray, 200, msg, pd);
if(s.showStatusAfterError) {
pd.progressDiv.hide();
pd.statusbar.append("<span class='" + s.errorClass + "'>ERROR: " + msg + "</span>");
} else {
pd.statusbar.hide();
pd.statusbar.remove();
}
obj.selectedFiles -= fileArray.length; //reduce selected File count
form.remove();
obj.fCounter += fileArray.length;
return;
}
obj.responses.push(data);
pd.progressbar.width('100%')
if(s.showProgress) {
pd.progressbar.html('100%');
pd.progressbar.css('text-align', 'center');
}
pd.abort.hide();
s.onSuccess.call(this, fileArray, data, xhr, pd);
if(s.showStatusAfterSuccess) {
if(s.showDone) {
pd.done.show();
pd.done.click(function () {
pd.statusbar.hide("slow");
pd.statusbar.remove();
});
} else {
pd.done.hide();
}
if(s.showDelete) {
pd.del.show();
pd.del.click(function () {
pd.statusbar.hide().remove();
if(s.deleteCallback) s.deleteCallback.call(this, data, pd);
obj.selectedFiles -= fileArray.length; //reduce selected File count
updateFileCounter(s, obj);
});
} else {
pd.del.hide();
}
} else {
pd.statusbar.hide("slow");
pd.statusbar.remove();
}
if(s.showDownload) {
pd.download.show();
pd.download.click(function () {
if(s.downloadCallback) s.downloadCallback(data);
});
}
form.remove();
obj.sCounter += fileArray.length;
},
error: function (xhr, status, errMsg) {
pd.abort.hide();
if(xhr.statusText == "abort") //we aborted it
{
pd.statusbar.hide("slow").remove();
updateFileCounter(s, obj);
} else {
s.onError.call(this, fileArray, status, errMsg, pd);
if(s.showStatusAfterError) {
pd.progressDiv.hide();
pd.statusbar.append("<span class='" + s.errorClass + "'>ERROR: " + errMsg + "</span>");
} else {
pd.statusbar.hide();
pd.statusbar.remove();
}
obj.selectedFiles -= fileArray.length; //reduce selected File count
}
form.remove();
obj.fCounter += fileArray.length;
}
};
if(s.showPreview && file != null) {
if(file.type.toLowerCase().split("/").shift() == "image") getSrcToPreview(file, pd.preview);
}
if(s.autoSubmit) {
form.ajaxSubmit(options);
} else {
if(s.showCancel) {
pd.cancel.show();
pd.cancel.click(function () {
removeExistingFileName(obj, fileArray);
form.remove();
pd.statusbar.remove();
s.onCancel.call(obj, fileArray, pd);
obj.selectedFiles -= fileArray.length; //reduce selected File count
updateFileCounter(s, obj);
});
}
form.ajaxForm(options);
}
}
return this;
}
}(jQuery));

View File

@@ -0,0 +1,39 @@
{
"name": "uploadfile",
"title": "jQuery Upload File",
"description": "jQuery Upload File plugin provides Multiple file Uploads with progress bar.Works with any server-side platform (Google App Engine, PHP, Python, Ruby on Rails, Java, etc.) that supports standard HTML form file uploads.",
"keywords": [
"jquery",
"upload",
"file",
"ajax",
"progressbar",
"multiple"
],
"version": "2.0.7",
"author": {
"name": "Ravishanker Kusuma",
"url": "http://hayageek.com"
},
"maintainers": [
{
"name": "Ravishanker Kusuma",
"email": "ravi@hayageek.com",
"url": "http://hayageek.com"
}
],
"licenses": [
{
"type": "MIT",
"url": "https://github.com/hayageek/jquery-upload-file/blob/master/MIT-License.txt"
}
],
"homepage": "https://github.com/hayageek/jquery-upload-file",
"docs": "http://hayageek.com/docs/jquery-upload-file.php",
"download": "https://github.com/hayageek/jquery-upload-file",
"demo": "http://hayageek.com/docs/jquery-upload-file.php",
"dependencies": {
"jquery": ">=1.6",
"form": ""
}
}

View File

@@ -0,0 +1,39 @@
{
"name": "uploadfile",
"title": "jQuery Upload File",
"description": "jQuery Upload File plugin provides Multiple file Uploads with progress bar.Works with any server-side platform (Google App Engine, PHP, Python, Ruby on Rails, Java, etc.) that supports standard HTML form file uploads.",
"keywords": [
"jquery",
"upload",
"file",
"ajax",
"progressbar",
"multiple"
],
"version": "3.1.10",
"author": {
"name": "Ravishanker Kusuma",
"url": "http://hayageek.com"
},
"maintainers": [
{
"name": "Ravishanker Kusuma",
"email": "ravi@hayageek.com",
"url": "http://hayageek.com"
}
],
"licenses": [
{
"type": "MIT",
"url": "https://github.com/hayageek/jquery-upload-file/blob/master/MIT-License.txt"
}
],
"homepage": "https://github.com/hayageek/jquery-upload-file",
"docs": "http://hayageek.com/docs/jquery-upload-file.php",
"download": "https://github.com/hayageek/jquery-upload-file",
"demo": "http://hayageek.com/docs/jquery-upload-file.php",
"dependencies": {
"jquery": ">=1.6",
"form": ""
}
}