更新了附件上传中的方法

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 = {
$('#file_upload').uploadify({ SessionID : '<?php echo session_id(); ?>'
'uploader' : '/static/js/uploadify/uploadify.swf', };
'scriptData': {'PHPSESSID' : '<?php echo session_id(); ?>'}, var uploader;
'script' : '/admin/data/upload/<?php if(!empty($this->uuid)) echo "uuid/".$this->uuid; ?>', var param;
'cancelImg' : '/static/js/uploadify/cancel.png', param = {
'folder' : '/uploads', "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, '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){ });
$.ajax({ var upload = {
'type': "POST", onsuccess : function(file, data, response){
'url': "/admin/data/attachments/", _data = $.parseJSON(data);
'data': 'uuid=<?php echo $this->uuid?>&mdattdel='+id, if(!$.isEmptyObject(_data.error))
'success': function(data){ {
if(data==null){Alert('遇到错误,请重试');return false;} alert(_data.error);
if(data.error!=null){Alert(data.error);return false;} }else{
if(data.status==1){$('#uploadedItem_'+id).fadeOut("slow");} $('#datalist').append(upload.makeFileHtml(_data));
}
}, },
'beforeSend':function(){}, makeFileHtml : function(data){
'complete':function(){}, return '<div class="alert alert-success">'
'timeout': 20000, + '<button type="button" class="close" data-dismiss="alert" onclick="upload.deleteFile('+data.id+')"><i class="icon-trash icon-white"></i></button>'
'dataType': 'json', + data.realname
'error': function(){Alert('处理中出现问题,请重试');} +'<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) { $.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']);
});
}); });
} }
}); });