fix upload

This commit is contained in:
joyqi 2013-10-14 17:14:37 +08:00
parent 1b1da9bfd7
commit 3ba9e2755e
2 changed files with 46 additions and 34 deletions

View File

@ -9,6 +9,41 @@ if (isset($post) && $post instanceof Typecho_Widget && $post->have()) {
<script>
$(document).ready(function() {
var errorWord = '<?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));
_e('附件上传失败, 请确认附件尺寸没有超过 %s 并且服务器附件目录可以写入', "{$val}Kb"); ?>';
function fileUploadStart (file, id) {
$('<li id="' + id + '" class="loading">'
+ file + '</li>').prependTo('#file-list');
}
function fileUploadComplete (id, url, data) {
var li = $('#' + id).removeClass('loading').data('cid', data.cid)
.data('url', data.url)
.data('image', data.isImage)
.html('<input type="hidden" name="attachment[]" value="' + data.cid + '" />'
+ '<a class="file" target="_blank" href="<?php $options->adminUrl('media.php'); ?>?cid='
+ data.cid + '">' + data.title + '</a> ' + data.bytes
+ ' <a class="insert" href="#"><?php _e('插入'); ?></a>'
+ ' <a class="delete" href="#">&times;</a>')
.effect('highlight', '#AACB36', 1000);
attachInsertEvent(li);
attachDeleteEvent(li);
}
$('.upload-file').fileUpload({
url : '<?php $options->index('/action/upload'
. (isset($fileParentContent) ? '?cid=' . $fileParentContent->cid : '')); ?>',
@ -23,39 +58,12 @@ $(document).ready(function() {
}
?>',
typesError : '<?php _e('附件 %s 的类型不被支持'); ?>',
onUpload : function (file, id) {
$('<li id="' + id + '" class="loading">'
+ file + '</li>').prependTo('#file-list');
},
onError : function (id, word) {
onUpload : fileUploadStart,
onError : function (id) {
$('#' + id).remove();
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;
}
_e('附件上传失败, 请确认附件尺寸没有超过 %s 并且服务器附件目录可以写入', "{$val} byte"); ?>');
},
onComplete : function (id, url, data) {
var li = $('#' + id).removeClass('loading').data('cid', data.cid)
.data('url', data.url)
.data('image', data.isImage)
.html('<input type="hidden" name="attachment[]" value="' + data.cid + '" />'
+ '<a class="file" target="_blank" href="<?php $options->adminUrl('media.php'); ?>?cid='
+ data.cid + '">' + data.title + '</a> ' + data.bytes
+ ' <a class="insert" href="#"><?php _e('插入'); ?></a>'
+ ' <a class="delete" href="#">&times;</a>')
.effect('highlight', '#AACB36', 1000);
attachInsertEvent(li);
attachDeleteEvent(li);
alert(errorWord);
},
onComplete : fileUploadComplete
});
$('#upload-panel').filedrop({
@ -72,7 +80,11 @@ $(document).ready(function() {
}
?>],
uploadStarted : function (i, file, len) {
console.log(file);
fileUploadStart(file.name, 'drag-' + i);
},
uploadFinished : function (i, file, response) {
fileUploadComplete('drag-' + i, response[0], response[1]);
}
});

View File

@ -308,7 +308,7 @@ class Widget_Upload extends Widget_Abstract_Contents implements Widget_Interface
$this->pluginHandle()->upload($this);
if ($this->request->isAjax()) {
$this->response->throwJson(array($this->request->_id, $this->attachment->url, array(
$this->response->throwJson(array($this->attachment->url, array(
'cid' => $insertId,
'title' => $this->attachment->name,
'type' => $this->attachment->type,
@ -386,7 +386,7 @@ class Widget_Upload extends Widget_Abstract_Contents implements Widget_Interface
$this->pluginHandle()->modify($this);
if ($this->request->isAjax()) {
$this->response->throwJson(array($this->request->_id, $this->attachment->url, array(
$this->response->throwJson(array($this->attachment->url, array(
'cid' => $this->cid,
'title' => $this->attachment->name,
'type' => $this->attachment->type,