更新了附件上传中的方法

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');
$files=new files();
$msg = $files -> upload($this->view->config->upload,$_FILES['Filedata'],empty($uuid)?'file':'md');
$files=new Files();
$msg = $files -> upload($_FILES['Filedata'],empty($uuid)?'file/':'md/',true);
if(empty($msg['error']))
{
@ -1797,7 +1797,7 @@ class Admin_DataController extends Zend_Controller_Action
$filename = $msg['db_path'];
$filesize = $msg['file_size'];
$filedesc = $this->_request->getParam('filedesc');
$filetype = $msg['file_type'];
$filetype = 'md';
$realname = $msg['realname'];
@ -2116,8 +2116,8 @@ class Admin_DataController extends Zend_Controller_Action
exit();
}
$files=new files();
$msg = $files -> upload($this->view->config->upload,$_FILES['Filedata'],empty($uuid)?'file':'md');
$files=new Files();
$msg = $files -> upload($_FILES['Filedata'],empty($uuid)?'file/':'md/',true);
if(empty($msg['error']))
{
@ -2125,7 +2125,7 @@ class Admin_DataController extends Zend_Controller_Action
$filename = $msg['db_path'];
$filesize = $msg['file_size'];
$filedesc = $this->_request->getParam('filedesc');
$filetype = $msg['file_type'];
$filetype = 'md';
$realname = $msg['realname'];
@ -2184,10 +2184,6 @@ class Admin_DataController extends Zend_Controller_Action
$rs = $this->db->query($sql);
$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);
exit();
}else

View File

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