21,890
社区成员
发帖
与我相关
我的任务
分享
//上传视频
/* 初始化上传插件 */
$("#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.');
}
});
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 src="' + src + '"/></div>'
);
} else {
updateAlert(data.info);
setTimeout(function(){
$('#top-alert').find('button').click();
$(that).removeMatch_type('disabled').prop('disabled',false);
},1500);
}
}
/* 上传图片 */
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 ) );
}

$("#file_upload").uploadify({
'uploader': '/Tools/ImgManageUpload',//'Content/uploadify/uploadify.php',
//指定swf文件
'swf': '/Content/uploadify/uploadify.swf',
//按钮显示的文字
'buttonText': '上传视频',
//上传文件的类型 默认为所有文件 'All Files' ; '*.*'
//在浏览窗口底部的文件类型下拉菜单中显示的文本
//'fileTypeDesc': 'Image Files',
'fileTypeDesc': '视频文件',
//允许上传的文件后缀
//'fileTypeExts': '*.gif; *.jpg; *.png',
'fileTypeExts': '*.avi; *.wmv; *.mp4;*.mp3; *.mov; *.flv; *.mkv; *.rmvb',//文件类型过滤
//发送给后台的其他参数通过formData指定
//'formData': { 'someKey': 'someValue', 'someOtherKey': 1 },
//上传文件页面中,你想要用来作为文件队列的元素的id, 默认为false 自动生成, 不带#
//'queueID': 'fileQueue',
//选择文件后自动上传
'auto': true,
//设置为true将允许多文件上传
'multi': false,
method: 'post',
//formData: { "imgType": "normal" }, //提交给服务器端的参数
'fileSizeLimit': '3000MB',//上传文件大小限制
onUploadSuccess: function (file, data, response) { //一个文件上传成功后的响应事件处理
console.info(data);
if (data != null) {
var data = $.parseJSON(data);
var path = data.rel;
//console.info(data.rel);
//$("#Img_Path").val(path);
//$("#Img_view").html('<img src=' + path + ' style="height:100px;:">')
}
else {
alert("上传出错");
}
},
onUploadError: function (file, errorCode, errorMsg, errorString) {
console.info(file);
console.info(errorCode);
console.info(errorMsg);
console.info(errorString);
}
});
use Think\Upload;
再次感谢!这个可能是调用thinkphp的什么upload模块,但我不知道相应的代码在哪里,哪里的代码限制了mp4文件上传。
'fileTypeExts' : '*.avi; *.rmvb; *.rm; *.asf; *.divx; *.mpg; *.mpeg; *.mpe; *.wmv; *.mp4; *.mkv; *.vob; *.gif;',
后缀是.mp4 应该没问题才对啊,都显示complate 和 success信息了,文件大小才600多k[/quote]
你这个是客户端的好不好。。。返回到信息是服务器端的,是你服务端限制了上传mp4,检查服务器端的
'fileTypeExts' : '*.avi; *.rmvb; *.rm; *.asf; *.divx; *.mpg; *.mpeg; *.mpe; *.wmv; *.mp4; *.mkv; *.vob; *.gif;',
后缀是.mp4 应该没问题才对啊,都显示complate 和 success信息了,文件大小才600多k
'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);
}

