Home > php教程 > php手册 > Yii Uploadify批量上传,yiiuploadify批量

Yii Uploadify批量上传,yiiuploadify批量

WBOY
Release: 2016-06-13 09:09:50
Original
1480 people have browsed it

Yii Uploadify批量上传,yiiuploadify批量

控制器:

 

$reinfo = "fail";
$filename="";
//重要说明:
//使用uploadify 上传时,每次这个sessionID都会改变,
//改变之后出现的不利影响就是无法再获取sessionID线下的其它session值,比如 Yii::app()->session['ik'] 值就变了。
//但是这个地方值不能变,仍要用 Yii::app()->session['ik'] 的值来作验证,
//因此一定要使用这句 session_id($pse); 作用是将sessionID改回来,与原来的sessionID一致,以便顺利获取值
//有了该值之后,原来的 sessionID 和 上传之后的 sessionID 是一致的。
//echo Yii::app()->session->sessionID; 这是Yii获取sessionID的方法
//2014-10-14 13:04 W.one
$pse = Yii::app()->request->getParam('PHPSESSION');
session_id($pse);
/*
* 如果不使用上句的话,Yii::app()->session['ik']==$who 是不可能相等的,因为sessionID变了
*/
$who = (int)Yii::app()->request->getParam('who');
$sjm = Yii::app()->request->getParam('sjm');
$zlsjm = Yii::app()->request->getParam("zlsjm");
//$xceikey = (int)Yii::app()->request->getParam('xceikey');//获取的相册ikey,默认为请选择,值为空,一定要选择一个值
if ($who==Yii::app()->session['ik']){
$sjz = time();
$tempFile = $_FILES['Filedata'];
$checkType = pathinfo($tempFile["name"],PATHINFO_EXTENSION);
if ($checkType != "notimg"){
$targetPath = $_SERVER['DOCUMENT_ROOT'] . '/oa/upload/file/';
$scfile = date("Y").date("m").date("d").date("His")."_".$who."_".md5(microtime()).".".$checkType;
$targetFile = str_replace('//','/',$targetPath) . $scfile;
if (move_uploaded_file($tempFile['tmp_name'],$targetFile)){
$relativeurl = "./upload/file/".$scfile;
//$relativeurl = $tempFile["name"];
$zlfj = new Zlfj();
$zlfj->fj_zlsjm = $zlsjm;
$zlfj->fj_uikey = Yii::app()->session["ik"];
$zlfj->fj_path = "./upload/file/".$scfile;
$zlfj->fj_time = time();
$zlfj->fj_name = $tempFile["name"];
if($zlfj->validate()&&$zlfj->save()){
$reinfo = $relativeurl;
$filename=$tempFile["name"];
}else{
@unlink($targetFile);
}

}
}
}
echo CJSON::encode(array("info"=>"$reinfo","name"=>$filename));

 

 

 

view:

 

//当用户选定文件,点确定后触发,每个文件将会触发一次
'onSelect':function(file){

},

'onUploadStart' : function(file) {
$("#xceimgs2").uploadify("settings", "formData",{'zlsjm':$("#juece_zlsjm").val(),'zlikey':$("#juece_zlikey").val()});
},

'onUploadSuccess':function(file, data, response){
json=eval("("+data+")");
//alert(json["name"]);return false;
//不等于fail表明上传成功
if(json.info!="fail"){
$("#jueceim"+ii).attr("src","");
$("#jueceb"+ii).text(json.name);
$("#juecedele"+ii).attr("src","");
$("#juecedele"+ii).attr("value",json.info);
ii++;
}
},

//返回一个错误,选择文件的时候触发
'onSelectError':function(file, errorCode, errorMsg){
switch(errorCode) {
case -100:
alert("上传的文件数量已经超出系统限制的 50 个文件!");
break;
case -110:
alert("文件 ["+file.name+"] 大小超出系统限制的"+$('#xceimgs2').uploadify('settings','fileSizeLimit')+"大小!");
break;
case -120:
alert("文件 ["+file.name+"] 大小异常!");
break;
case -130:
alert("文件 ["+file.name+"] 类型不正确!");
break;
default:
}
}
});
});

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template