更新了附件上传中的方法

This commit is contained in:
Li Jianxuan 2013-10-16 08:07:54 +00:00
parent 29557c14c1
commit 3acef46848
2 changed files with 78 additions and 72 deletions

View File

@ -1788,8 +1788,8 @@ class Admin_DataController extends Zend_Controller_Action
$id = $this->_getParam('attupdate'); $id = $this->_getParam('attupdate');
$files=new files(); $files=new Files();
$msg = $files -> upload($this->view->config->upload,$_FILES['Filedata'],empty($uuid)?'file':'md'); $msg = $files -> upload($_FILES['Filedata'],empty($uuid)?'file/':'md/',true);
if(empty($msg['error'])) if(empty($msg['error']))
{ {
@ -1797,7 +1797,7 @@ class Admin_DataController extends Zend_Controller_Action
$filename = $msg['db_path']; $filename = $msg['db_path'];
$filesize = $msg['file_size']; $filesize = $msg['file_size'];
$filedesc = $this->_request->getParam('filedesc'); $filedesc = $this->_request->getParam('filedesc');
$filetype = $msg['file_type']; $filetype = 'md';
$realname = $msg['realname']; $realname = $msg['realname'];
@ -2116,8 +2116,8 @@ class Admin_DataController extends Zend_Controller_Action
exit(); exit();
} }
$files=new files(); $files=new Files();
$msg = $files -> upload($this->view->config->upload,$_FILES['Filedata'],empty($uuid)?'file':'md'); $msg = $files -> upload($_FILES['Filedata'],empty($uuid)?'file/':'md/',true);
if(empty($msg['error'])) if(empty($msg['error']))
{ {
@ -2125,7 +2125,7 @@ class Admin_DataController extends Zend_Controller_Action
$filename = $msg['db_path']; $filename = $msg['db_path'];
$filesize = $msg['file_size']; $filesize = $msg['file_size'];
$filedesc = $this->_request->getParam('filedesc'); $filedesc = $this->_request->getParam('filedesc');
$filetype = $msg['file_type']; $filetype = 'md';
$realname = $msg['realname']; $realname = $msg['realname'];
@ -2184,10 +2184,6 @@ class Admin_DataController extends Zend_Controller_Action
$rs = $this->db->query($sql); $rs = $this->db->query($sql);
$atts = $rs->fetchAll(); $atts = $rs->fetchAll();
foreach($atts as $k=>$v)
{
$atts[$k]['html']= $v['realname'].'['. round($v['filesize']/1024,2) .' kb]<input type="hidden" name="atts[]" value="'.$v['id'].'" /><div class="cancel"><a href="javascript:;" id="deletebtn_'.$v['id'].'"><img border="0" src="/static/js/uploadify/cancel.png" /></a></div>';
}
echo Zend_Json::encode($atts); echo Zend_Json::encode($atts);
exit(); exit();
}else }else

View File

@ -7,12 +7,7 @@
$this->breadcrumb('<a href="/admin">后台首页</a>'); $this->breadcrumb('<a href="/admin">后台首页</a>');
$this->breadcrumb('数据管理'); $this->breadcrumb('数据管理');
$this->breadcrumb()->setSeparator(' > '); $this->breadcrumb()->setSeparator(' > ');
$this->headLink()->appendStylesheet('/static/js/uploadify/uploadify.css'); $this->theme->AppendPlus($this,"uploadify");
$this->headScript()->appendFile('/static/js/jquery-1.7.2.min.js');
$this->headScript()->appendFile('/js/jquery.colorbox-min.js');
$this->headLink()->appendStylesheet('/css/colorbox.css');
$this->headScript()->appendFile('/static/js/uploadify/swfobject.js');
$this->headScript()->appendFile('/static/js/uploadify/jquery.uploadify.v2.1.4.min.js');
?> ?>
<div id="leftPanel"> <div id="leftPanel">
<?= $this->partial('data/left.phtml'); ?> <?= $this->partial('data/left.phtml'); ?>
@ -30,7 +25,8 @@
<input type="hidden" name="submit" value="1" /> <input type="hidden" name="submit" value="1" />
<p>注:可选择多个文件<br /> <p>注:可选择多个文件<br />
<ul id="datalist"></ul> <div id="datalist">
</div>
<input id="file_upload" name="Filedata" type="file" /> <input id="file_upload" name="Filedata" type="file" />
<input type="button" class="btn btn-small" onclick="$('#file_upload').uploadifyUpload();" value="上传" /> <input type="button" class="btn btn-small" onclick="$('#file_upload').uploadifyUpload();" value="上传" />
</p> </p>
@ -38,65 +34,79 @@
</form> </form>
</div> </div>
<script> <script>
$(document).ready(function() { var _this = {
SessionID : '<?php echo session_id(); ?>'
};
var uploader;
var param;
param = {
"PHPSESSID" : _this.SessionID,
"multi" : 'yes'
};
$(function() {
$('#file_upload').uploadify({ $('#file_upload').uploadify({
'uploader' : '/static/js/uploadify/uploadify.swf', 'swf' : '/js/lib/uploadify/uploadify.swf',
'scriptData': {'PHPSESSID' : '<?php echo session_id(); ?>'}, 'uploader' : '/admin/data/upload/<?php if(!empty($this->uuid)) echo "uuid/".$this->uuid; ?>',
'script' : '/admin/data/upload/<?php if(!empty($this->uuid)) echo "uuid/".$this->uuid; ?>',
'cancelImg' : '/static/js/uploadify/cancel.png',
'folder' : '/uploads',
'multi' : true, 'multi' : true,
'auto' : false, 'auto' : true,
'displayData' : 'speed', 'fileTypeExts' : '*',
'buttonImg' : '/static/js/uploadify/selectfile.gif', 'onUploadSuccess' : function(file, data, response) {
'onComplete' : function(event, ID, fileObj, response, data) { upload.onsuccess(file, data, response);
var obj = jQuery.parseJSON(response);
var html;
if(obj.error=='')
{html = obj.html;}else{html = obj.error;}
$('<li/>', {
"id":'uploadedItem_'+obj.attid,
"class":'uploadifyQueueItem',
"html": html
}).appendTo('#datalist');
$('#deletebtn_'+obj.attid).bind('click', function() {
deleteatt(obj.attid);
});
}, },
'onError' : function (event,ID,fileObj,errorObj) { 'onUploadStart' : function(file) {
alert(errorObj.type + ' Error: ' + errorObj.info); $('#file_upload').uploadify('settings','formData',param);
} }
}); });
function deleteatt(id){ });
var upload = {
onsuccess : function(file, data, response){
_data = $.parseJSON(data);
if(!$.isEmptyObject(_data.error))
{
alert(_data.error);
}else{
$('#datalist').append(upload.makeFileHtml(_data));
}
},
makeFileHtml : function(data){
return '<div class="alert alert-success">'
+ '<button type="button" class="close" data-dismiss="alert" onclick="upload.deleteFile('+data.id+')"><i class="icon-trash icon-white"></i></button>'
+ data.realname
+'<input type="hidden" name="attid" value="'+data.id+'"></input>'
+'</div>';
},
deleteFile : function(id){
$.ajax({ $.ajax({
'type':"POST", 'type':"POST",
'url': "/admin/data/attachments/", 'url':'/admin/data/attachments/',
'data':'uuid=<?php echo $this->uuid?>&mdattdel='+id, 'data':'uuid=<?php echo $this->uuid?>&mdattdel='+id,
'success':function(data){ 'success':function(data){
if(data==null){Alert('遇到错误,请重试');return false;} if(typeof(data) == 'undefined')
if(data.error!=null){Alert(data.error);return false;} {
if(data.status==1){$('#uploadedItem_'+id).fadeOut("slow");} alert("数据源错误,请联系管理员");
}, return false;
'beforeSend':function(){},
'complete':function(){},
'timeout': 20000,
'dataType': 'json',
'error': function(){Alert('处理中出现问题,请重试');}
});
} }
if(!$.isEmptyObject(data.error))
{
alert(data.error);
return false;
}
},
'timeout': 30000,
'error': function(){
alert('附件删除出错');
}
});
}
};
$(document).ready(function() {
$.getJSON("/admin/data/getatts/uuid/<?php echo $this->uuid;?>", function(data) { $.getJSON("/admin/data/getatts/uuid/<?php echo $this->uuid;?>", function(data) {
if(data) if(data)
{ {
$.each(data, function(key, val) { $.each(data, function(key, val) {
$('<li/>', { $('#datalist').append(upload.makeFileHtml(val));
"id":'uploadedItem_'+val['id'],
"class":'uploadifyQueueItem',
"html": val['html']
}).appendTo('#datalist');
$('#deletebtn_'+val['id']).bind('click', function() {
deleteatt(val['id']);
});
}); });
} }
}); });