21,886
社区成员
发帖
与我相关
我的任务
分享
<div class="form-item">
<label class="item-label">视频</label>
<div class="controls">
<input type="file" id="upload_video">
<input type="hidden" name="video" id="vid" value="{$people.video}"/>
<div class="upload-video-box">
<notempty name="people.video">
<div class="upload-pre-item">
<video width="602px" height="345px" controls="controls">
<source src="__ROOT__/{$people.video}" type="video/mp4"></source>
</video>
</div>
</notempty>
</div>
</div>
</div>
//上传视频
/* 初始化上传插件 */
$("#upload_video").uploadify({
"height" : 400,
"swf" : "__STATIC__/uploadify/uploadify.swf",
"fileObjName" : "download",
"buttonText" : "上传视频",
"uploader" : "{:U('File/uploadPicture',array('session_id'=>session_id()))}",
"width" : 600,
'removeTimeout' : 1,
'fileTypeExts' : '*.avi; *.rmvb; *.rm; *.asf; *.divx; *.mpg; *.mpeg; *.mpe; *.wmv; *.mp4; *.mkv; *.vob; *.gif;',
'fileSizeLimit' : '1024M',
"onUploadSuccess" : uploadVideoFrontvideo,
'onFallback' : function() {
alert('未检测到兼容版本的Flash.');
},
'onUploadSuccess' : function(file, data, response) {
//alert(file.name + ' | ' + response + ':' + data);
},
'onUploadError' : function(file, errorCode, errorMsg, errorString) {
alert('The file ' + file.name + ' could not be uploaded: ' + errorString);
}
});
function uploadVideoFrontvideo(file, data){
var data = $.parseJSON(data);
var src = '';
if(data.status){
$("#vid").val(data.path);
src = data.url || '__ROOT__' + data.path
$("#vid").parent().find('.upload-video-box').html(
'<div class="upload-pre-item"><video width="602px" height="345px" controls="controls"><source src="' + src + '" type="video/mp4"></source></video></div>'
);
} else {
updateAlert(data.info);
setTimeout(function(){
$('#top-alert').find('button').click();
$(that).removeMatch_type('disabled').prop('disabled',false);
},1500);
}
}
use Think\Upload;
...
//====================================富文本框===========================
/* 上传图片 */
public function upload() {
/* 上传配置 */
$setting = C ( 'EDITOR_UPLOAD' );
$setting ['callback'] = array (
$this
);
/* 调用文件上传组件上传文件 */
$this->uploader = new Upload ( $setting, 'Local' );
$info = $this->uploader->upload ( $_FILES );
// dump($info);
if ($info) {
$dao = D ( 'Picture', 'Home' );
foreach ( $info as &$file ) {
$file ['rootpath'] = __ROOT__ . ltrim ( $setting ['rootPath'], "." );
/* 已经存在文件记录 */
if (isset ( $file ['id'] ) && is_numeric ( $file ['id'] )) {
$file ['path'] = __ROOT__ . ltrim ( $file ['path'], "." );
continue;
}
/* 记录文件信息 */
$file ['path'] = __ROOT__ . ltrim ( $setting ['rootPath'], "." ) . $file ['savepath'] . $file ['savename'];
$file ['status'] = 1;
$file ['create_time'] = NOW_TIME;
if ($dao->create ( $file ) && ($id = $dao->add ())) {
$file ['id'] = $id;
}
}
}
return $info;
}
// keditor编辑器上传图片处理
public function ke_upimg() {
/* 返回标准数据 */
$return = array (
'error' => 0,
'info' => '上传成功',
'data' => ''
);
$info = $this->upload();
$img = $info ['imgFile'] ['path'];
/* 记录附件信息 */
if ($img) {
$return ['id'] = $info ['imgFile'] ['id'];
$return ['url'] = $img;
unset ( $return ['info'], $return ['data'] );
} else {
$return ['error'] = 1;
$return ['message'] = $this->uploader->getError ();
}
/* 返回JSON数据 */
exit ( json_encode ( $return ) );
}
/* 上传视频 */
public function upload_v() {
// 上传配置
$setting = C ( 'EDITOR_UPLOAD' );
$setting ['callback'] = array (
$this
);
// 调用文件上传组件上传文件
$this->uploader = new Upload ( $setting, 'Local' );
$info = $this->uploader->upload ( $_FILES );
dump($info);
if ($info) {
$dao = D ( 'Picture', 'Home' );
foreach ( $info as &$file ) {
$file ['rootpath'] = __ROOT__ . ltrim ( $setting ['rootPath'], "." );
// 已经存在文件记录
if (isset ( $file ['id'] ) && is_numeric ( $file ['id'] )) {
$file ['path'] = __ROOT__ . ltrim ( $file ['path'], "." );
continue;
}
// 记录文件信息
$file ['path'] = __ROOT__ . ltrim ( $setting ['rootPath'], "." ) . $file ['savepath'] . $file ['savename'];
$file ['status'] = 1;
$file ['create_time'] = NOW_TIME;
if ($dao->create ( $file ) && ($id = $dao->add ())) {
$file ['id'] = $id;
}
}
}
return $info;
}
// keditor编辑器上传视频处理
public function ke_upvideo() { // 没用到
/* 返回标准数据 */
$return = array (
'error' => 0,
'info' => '上传成功',
'data' => ''
);
$info = $this->upload_v();
$video = $info ['videoFile'] ['path'];
/* 记录附件信息 */
if ($video) {
$return ['id'] = $info ['videoFile'] ['id'];
$return ['url'] = $video;
unset ( $return ['info'], $return ['data'] );
} else {
$return ['error'] = 1;
$return ['message'] = $this->uploader->getError ();
}
/* 返回JSON数据 */
exit ( json_encode ( $return ) );
}
$dao = D ( 'Picture', 'Home' );
//富文本框
var editor;
KindEditor.ready(function(K) {
editor = K.create('textarea[name="summary"]', {
allowFileManager : false,
themesPath: K.basePath,
width: '100%',
height: '500px',
resizeType: 1,
pasteType : 2,
urlType : 'absolute',
fileManagerJson : '{:U('fileManagerJson')}',
//uploadJson : '{:U('uploadJson')}' }
uploadJson : '{:U("people/ke_upimg")}'
});
});
这段代码似乎只能传图片的json数据,要是再加上以下代码来传视频的JSON数据好像就会出错了:
//富文本框 // cjq add
var editor1;
KindEditor1.ready(function(K) {
editor1 = K.create('textarea[name="summary"]', {
allowFileManager : false,
themesPath: K.basePath,
width: '100%',
height: '500px',
resizeType: 1,
pasteType : 2,
urlType : 'absolute',
fileManagerJson : '{:U('fileManagerJson')}',
//uploadJson : '{:U('uploadJson')}' }
uploadJson : '{:U("people/ke_upvideo")}'
});
});
怎么办呢?请知道的人不吝赐教!