Skip to content

Commit

Permalink
文件上传搞定,支持一次拖拽多个
Browse files Browse the repository at this point in the history
  • Loading branch information
joyqi committed Oct 14, 2013
1 parent 944ce1e commit 0ed15a2
Show file tree
Hide file tree
Showing 5 changed files with 640 additions and 561 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@
*.sublime*
.sass-cache
config.rb
/config.inc.php
/config.inc.php
/usr/uploads/
8 changes: 7 additions & 1 deletion admin/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -2004,6 +2004,12 @@ ul.typecho-list-notable li .loading {
color: #999;
font-size: .92857em;
}

#upload-panel.drag {
border-color: #ccc;
background-color: #e3e3e3;
}

#file-list {
list-style: none;
margin: 0;
Expand Down Expand Up @@ -2186,4 +2192,4 @@ div.token-input-dropdown ul li em {
div.token-input-dropdown ul li.token-input-selected-dropdown-item {
background-color: #467B96;
color: #FFF;
}
}
78 changes: 74 additions & 4 deletions admin/file-upload-js.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
}
?>

<script src="<?php $options->adminUrl('javascript/filedrop.js?v=' . $suffixVersion); ?>"></script>
<script>
$(document).ready(function() {
var errorWord = '<?php $val = function_exists('ini_get') ? trim(ini_get('upload_max_filesize')) : 0;
Expand All @@ -21,8 +22,10 @@
$val *= 1024;
}

$val = number_format(ceil($val / 1024));
_e('附件上传失败, 请确认附件尺寸没有超过 %s 并且服务器附件目录可以写入', "{$val}Kb"); ?>';
$val = number_format(ceil($val / (1024 *1024)));
_e('附件上传失败, 请确认附件尺寸没有超过 %s 并且服务器附件目录可以写入', "{$val}Mb"); ?>',
loading = $('<img src="<?php $options->adminUrl('images/ajax-loader.gif'); ?>" style="display:none" />')
.appendTo(document.body);

function fileUploadStart (file, id) {
$('<li id="' + id + '" class="loading">'
Expand Down Expand Up @@ -79,7 +82,72 @@ function fileUploadComplete (id, url, data) {
}
}
?>],
uploadStarted : function (i, file, len) {

maxfilesize : <?php
$val = function_exists('ini_get') ? trim(ini_get('upload_max_filesize')) : 0;
$last = strtolower($val[strlen($val)-1]);
switch($last) {
// The 'G' modifier is available since PHP 5.1.0
case 'g':
$val *= 1024;
case 'm':
$val *= 1024;
case 'k':
$val *= 1024;
}

echo ceil($val / (1024 * 1024));
?>,

error: function(err, file) {
switch(err) {
case 'BrowserNotSupported':
alert('<?php _e('浏览器不支持拖拽上传'); ?>');
break;
case 'TooManyFiles':
alert('<?php _e('一次上传的文件不能多于%d个', 25); ?>');
break;
case 'FileTooLarge':
alert('<?php $val = function_exists('ini_get') ? trim(ini_get('upload_max_filesize')) : 0;
$last = strtolower($val[strlen($val)-1]);
switch($last) {
// The 'G' modifier is available since PHP 5.1.0
case 'g':
$val *= 1024;
case 'm':
$val *= 1024;
case 'k':
$val *= 1024;
}

$val = number_format(ceil($val / (1024 *1024)));
_e('附件尺寸不能超过 %s', "{$val}Mb"); ?>');
break;
case 'FileTypeNotAllowed':
// The file type is not in the specified list 'allowedfiletypes'
break;
case 'FileExtensionNotAllowed':
alert('<?php _e('附件 %s 的类型不被支持'); ?>'.replace('%s', file.name));
break;
default:
break;
}
},


dragOver : function () {
$(this).addClass('drag');
},

dragLeave : function () {
$(this).removeClass('drag');
},

drop : function () {
$(this).removeClass('drag');
},

uploadOpened : function (i, file, len) {
fileUploadStart(file.name, 'drag-' + i);
},

Expand Down Expand Up @@ -109,7 +177,9 @@ function attachDeleteEvent (el) {
$.post('<?php $options->index('/action/contents-attachment-edit'); ?>',
{'do' : 'delete', 'cid' : cid},
function () {
el.remove();
$(el).fadeOut(function () {
$(this).remove();
});
});
}

Expand Down
Loading

0 comments on commit 0ed15a2

Please sign in to comment.