1.添加方法:打开Application/Admin/Common/function.php文件,找到function get_attribute_type($type=”),
在第86行下添加一项:
’uploadpics’ => array(‘批量上传图片’,’varchar(255) NOT NULL’),
注意使用英文符号,添加这一项后,你在后台添加字段的时候就可以进行选择了,不过要实现功能你还需要修改一些东西。
修改你的模板(如添加文章、修改文章模板),比如:
一. 文件 Application/Admin/View/Article/add.html。在<case value=”picture”>…</case>下添加如下代码:
<case value="uploadpics">
<!-- 批量上传图片 -->
<input type="file" id="upload_all_{$field.name}">
<input type="hidden" name="{$field.name}" value="{$data[$field['name']]}" id="input_upload_all_{$field.name}"/>
<div id="uploadpics_piclist_{$field.name}">
<ul class="highslide-gallery">
<notempty name="data[$field['name']]">
<?php
$pics=explode(',', $data[$field['name']]);
foreach($pics as $v){
if($v!=''){
?>
<li><a href="__ROOT__{$v|get_cover='path'}"><img src="__ROOT__{$v|get_cover='path'}" onclick="delthispic(this)" dataid="{$v},"/></a></li>
<?php
}
}
?>
</notempty>
</ul>
</div>
<script type="text/javascript">
//批量上传图片
/* 初始化上传插件 */
$("#upload_all_{$field.name}").uploadify({
"height" : 30,
"swf" : "__STATIC__/uploadify/uploadify.swf",
"fileObjName" : "download",
"buttonText" : "批量上传图片",
"uploader" : "{:U('File/uploadPicture',array('session_id'=>session_id()))}",
"width" : 120,
'removeTimeout' : 1,
'fileTypeExts' : '*.jpg; *.png; *.gif;',
"onUploadSuccess" : uploadAll{$field.name},
'onFallback' : function() {
alert('未检测到兼容版本的Flash.');
}
});
function uploadAll{$field.name}(file, data){
var data = $.parseJSON(data);
var src = '';
if(data.status){
src = data.url || '__ROOT__' + data.path;
var value = '<li><img src="' + src + '" onclick="delthispic(this)" dataid="'+data.id+',"/></li>';
$('#input_upload_all_{$field.name}').val($('#input_upload_all_{$field.name}').val()+data.id+',');
$('#uploadpics_piclist_{$field.name} ul').append(value);
} else {
updateAlert(data.info);
setTimeout(function(){
$('#top-alert').find('button').click();
$(that).removeClass('disabled').prop('disabled',false);
},1500);
}
}
function delthispic(obj){
var dataid=$(obj).attr('dataid');
$('#input_upload_all_{$field.name}').val($('#input_upload_all_{$field.name}').val().replace(dataid, ""));
$(obj).parent().remove();
}
</script>
</case>
二. 文件 Application/Admin/View/Article/edit.html。在<case value=”picture”>…</case>下添加如下代码:
<case value="uploadpics">
<!-- 批量上传图片 -->
<input type="file" id="upload_all_{$field.name}">
<input type="hidden" name="{$field.name}" value="{$data[$field['name']]}" id="input_upload_all_{$field.name}"/>
<div id="uploadpics_piclist_{$field.name}">
<ul class="highslide-gallery">
<notempty name="data[$field['name']]">
<?php
$pics=explode(',', $data[$field['name']]);
foreach($pics as $v){
if($v!=''){
?>
<li><img src="{$v|get_cover='path'}" onclick="delthispic(this)" dataid="{$v},"/></li>
<?php
}
}
?>
</notempty>
</ul>
</div>
<script type="text/javascript">
//批量上传图片
/* 初始化上传插件 */
$("#upload_all_{$field.name}").uploadify({
"height" : 30,
"swf" : "__STATIC__/uploadify/uploadify.swf",
"fileObjName" : "download",
"buttonText" : "批量上传图片",
"uploader" : "{:U('File/uploadPicture',array('session_id'=>session_id()))}",
"width" : 120,
'removeTimeout' : 1,
'fileTypeExts' : '*.jpg; *.png; *.gif;',
"onUploadSuccess" : uploadAll{$field.name},
'onFallback' : function() {
alert('未检测到兼容版本的Flash.');
}
});
function uploadAll{$field.name}(file, data){
var data = $.parseJSON(data);
var src = '';
if(data.status){
src = data.url || '__ROOT__' + data.path;
var value = '<li><img src="' + src + '" onclick="delthispic(this)" dataid="'+data.id+',"/></li>';
$('#input_upload_all_{$field.name}').val($('#input_upload_all_{$field.name}').val()+data.id+',');
$('#uploadpics_piclist_{$field.name} ul').append(value);
} else {
updateAlert(data.info);
setTimeout(function(){
$('#top-alert').find('button').click();
$(that).removeClass('disabled').prop('disabled',false);
},1500);
}
}
function delthispic(obj){
var dataid=$(obj).attr('dataid');
$('#input_upload_all_{$field.name}').val($('#input_upload_all_{$field.name}').val().replace(dataid, ""));
$(obj).parent().remove();
}
</script>
</case>
3.在后台样式文件添加样式,控制图片大小,如:/Public/Admin/css/style.css文件,
/* 多图片上传 */
.highslide-gallery li{
120px;
}
这样就实现多图片上传了,其他文件类似修改;
原网址链接:http://www.cnblogs.com/manongxiaobing/p/4727410.html