Skip to content

Commit

Permalink
Merge pull request #12 from jakeuj/feature/fixFileType
Browse files Browse the repository at this point in the history
* Use file extension to check file type
  • Loading branch information
RonnieSan committed Jun 30, 2021
2 parents 0ccaa5d + eab99ef commit 3d0b19a
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Sample/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
$('#file_upload').uploadifive({
'auto' : false,
'checkScript' : 'check-exists.php',
'fileType' : 'image/png',
'fileType' : '.jpg,.jpeg,.gif,.png',
'formData' : {
'timestamp' : '<?php echo $timestamp;?>',
'token' : '<?php echo md5('unique_salt' . $timestamp);?>'
Expand Down
19 changes: 13 additions & 6 deletions Sample/jquery.uploadifive.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
UploadiFive 1.2.3
Copyright (c) 2012 Reactive Apps, Ronnie Garcia
Released under the UploadiFive Standard License <http://www.uploadify.com/uploadifive-standard-license>
Released under the MIT License
*/
;(function($) {

Expand Down Expand Up @@ -45,7 +45,7 @@ Released under the UploadiFive Standard License <http://www.uploadify.com/upload
'dropTarget' : false, // Selector for the drop target
'fileObjName' : 'Filedata', // The name of the file object to use in your server-side script
'fileSizeLimit' : 0, // Maximum allowed size of files to upload
'fileType' : false, // Type of files allowed (image, etc), separate with a pipe character |
'fileType' : false, // Extension of files allowed (.zip,.rar,.7z,.pdf,...ETC.), separate with a comma character ,
'formData' : {}, // Additional data to send to the upload script
'height' : 30, // The height of the button
'itemTemplate' : false, // The HTML markup for the item in the queue
Expand Down Expand Up @@ -84,7 +84,7 @@ Released under the UploadiFive Standard License <http://www.uploadify.com/upload
// Create an array of file types
var file_types;
if (settings.fileType) {
file_types = settings.fileType.split('|');
file_types = settings.fileType.split(',');
}

// Calculate the file size limit
Expand Down Expand Up @@ -207,9 +207,11 @@ Released under the UploadiFive Standard License <http://www.uploadify.com/upload
for (var n = 0; n < limit; n++) {
file = fileData.files[n];
$data.addQueueItem(file);
if (file_types && file_types.indexOf(file.type) === -1) {
$data.error('FORBIDDEN_FILE_TYPE', file);
}
// Check the filetype
if (file_types) {
if(file_types.indexOf(file.name.substring(file.name.lastIndexOf('.')))<0)
$data.error('FORBIDDEN_FILE_TYPE', file);
}
}
// Save the data to the inputs object
$data.inputs[inputName] = fileData;
Expand Down Expand Up @@ -297,6 +299,11 @@ Released under the UploadiFive Standard License <http://www.uploadify.com/upload
// Trigger the addQueueItem event
if (typeof settings.onAddQueueItem === 'function') {
settings.onAddQueueItem.call($this, file);
}
// Check the filetype
if (file_types) {
if(file_types.indexOf(file.name.substring(file.name.lastIndexOf('.')))<0)
$data.error('FORBIDDEN_FILE_TYPE', file);
}
// Check the filesize
if (file.size > settings.fileSizeLimit && settings.fileSizeLimit !== 0) {
Expand Down
2 changes: 1 addition & 1 deletion Sample/jquery.uploadifive.min.js

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions change-log.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
UploadiFive Change Log

v1.3.0
* Use file extension to check file type
* Use comma character ',' to separate extension of files type allowed
* Fixed file type option when selecting files
* Fixed file type option when dropping files

v1.2.3
* Fixed file type option when dropping files
Expand Down
17 changes: 12 additions & 5 deletions jquery.uploadifive.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Released under the MIT License
'dropTarget' : false, // Selector for the drop target
'fileObjName' : 'Filedata', // The name of the file object to use in your server-side script
'fileSizeLimit' : 0, // Maximum allowed size of files to upload
'fileType' : false, // Type of files allowed (image, etc), separate with a pipe character |
'fileType' : false, // Extension of files allowed (.zip,.rar,.7z,.pdf,...ETC.), separate with a comma character ,
'formData' : {}, // Additional data to send to the upload script
'height' : 30, // The height of the button
'itemTemplate' : false, // The HTML markup for the item in the queue
Expand Down Expand Up @@ -84,7 +84,7 @@ Released under the MIT License
// Create an array of file types
var file_types;
if (settings.fileType) {
file_types = settings.fileType.split('|');
file_types = settings.fileType.split(',');
}

// Calculate the file size limit
Expand Down Expand Up @@ -207,9 +207,11 @@ Released under the MIT License
for (var n = 0; n < limit; n++) {
file = fileData.files[n];
$data.addQueueItem(file);
if (file_types && file_types.indexOf(file.type) === -1) {
$data.error('FORBIDDEN_FILE_TYPE', file);
}
// Check the filetype
if (file_types) {
if(file_types.indexOf(file.name.substring(file.name.lastIndexOf('.')))<0)
$data.error('FORBIDDEN_FILE_TYPE', file);
}
}
// Save the data to the inputs object
$data.inputs[inputName] = fileData;
Expand Down Expand Up @@ -297,6 +299,11 @@ Released under the MIT License
// Trigger the addQueueItem event
if (typeof settings.onAddQueueItem === 'function') {
settings.onAddQueueItem.call($this, file);
}
// Check the filetype
if (file_types) {
if(file_types.indexOf(file.name.substring(file.name.lastIndexOf('.')))<0)
$data.error('FORBIDDEN_FILE_TYPE', file);
}
// Check the filesize
if (file.size > settings.fileSizeLimit && settings.fileSizeLimit !== 0) {
Expand Down
2 changes: 1 addition & 1 deletion jquery.uploadifive.min.js

Large diffs are not rendered by default.

0 comments on commit 3d0b19a

Please sign in to comment.