377 lines
10 KiB
PHP
377 lines
10 KiB
PHP
<?php
|
|
/**
|
|
* 上传文件
|
|
*
|
|
* @author:administrator
|
|
* @createTime:2016-07-03
|
|
*
|
|
*/
|
|
include_once('UserLoginQ2.class.php');
|
|
include_once('UploadResult.class.php');
|
|
include_once('DoiRegResult.class.php');
|
|
|
|
class UploadFileQ2 {
|
|
|
|
var $filePath;// 源文件路径,要上传的文件的全路径包括文件名
|
|
var $userId;// 用户id
|
|
var $companyType;// 机构类型
|
|
//var $doiurl="127.0.0.1:8080/chinadoi-portal";
|
|
var $ip=null;
|
|
// 构造方法
|
|
function __construct() {
|
|
|
|
}
|
|
/**
|
|
*
|
|
* @param filePath 源文件路径,要上传的文件的全路径包括文件名
|
|
* @param userId 用户id
|
|
* @param companyType 机构类型
|
|
* @return 上传结果 文件上传成功
|
|
文件名、目录名或卷标语法不正确
|
|
请输入文件名称
|
|
您输入的文件名含有非法字符
|
|
已有同名文件夹
|
|
文件重命名错误请与管理员联系或者重新上传
|
|
插入记录有错误请与管理员联系
|
|
文件不存在
|
|
服务器连接失败
|
|
*/
|
|
|
|
function upload( $filePath, $username, $password, $oprType){
|
|
|
|
$CUserLoginO2X=new UserLoginQ2();
|
|
|
|
if(empty($this->ip)) $this->ip=SERVERIP;
|
|
|
|
$ip=$this->ip;
|
|
|
|
$loginresult=$CUserLoginO2X->userlogin($username, $password,$ip);
|
|
|
|
if($loginresult->loginState!=="登录成功") return $loginresult->loginState;
|
|
|
|
return $this->uploadX1($filePath, $loginresult->userId, $loginresult->companyType,$oprType);
|
|
}
|
|
|
|
|
|
function upload2( $filePath, $username, $password, $oprType){
|
|
|
|
$CUserLoginO2X=new UserLoginQ2();
|
|
|
|
if(empty($this->ip)) $this->ip=SERVERIP;
|
|
|
|
$ip=$this->ip;
|
|
|
|
$loginresult=$CUserLoginO2X->userlogin($username, $password,$ip);
|
|
|
|
if($loginresult->loginState!=="登录成功") return $loginresult->loginState;
|
|
|
|
return $this->uploadX2($filePath, $loginresult->userId, $loginresult->companyType,$oprType);
|
|
}
|
|
|
|
function uploadX1($targetFile, $userId, $companyType, $oprType) {
|
|
|
|
|
|
$rtn="文件上传失败";
|
|
|
|
$cookie_file = COOKIEFILE;
|
|
|
|
if(!file_exists($cookie_file))
|
|
{
|
|
|
|
echo "cookie_file is not exists!";
|
|
|
|
die();
|
|
}
|
|
|
|
$this->userId=$userId;
|
|
$this->companyType=$companyType;
|
|
|
|
$upurl=$this->ip."/chinadoi-manage/manage/doidata-upload.action";
|
|
$ch = curl_init();
|
|
curl_setopt($ch, CURLOPT_URL,$upurl );
|
|
curl_setopt($ch, CURLOPT_HEADER, 0);
|
|
curl_setopt($ch, CURLOPT_VERBOSE, 0);
|
|
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
|
|
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible;)");
|
|
//curl_setopt($ch, CURLOPT_URL, _VIRUS_SCAN_URL);
|
|
curl_setopt($ch, CURLOPT_POST, true);
|
|
|
|
$post = array(
|
|
"fileForm_upload"=>"@$targetFile",
|
|
"upload"=>"@$targetFile",
|
|
"OTList"=>"DOI注册",
|
|
"userId"=> $this->userId,
|
|
"companyType"=> $this->companyType,
|
|
"clientState"=> true,
|
|
"pageType"=> "clientUpFile",
|
|
|
|
"mes"=> "",
|
|
"allUpSpace"=> "1000",
|
|
"upFileSpace"=> "15.0",
|
|
"oddSpace"=> "999.96",
|
|
"rootPath"=> "E:/chinadoi/backup/UserFiles/552",
|
|
"filePath"=> "/待审核的文件/追加数据",
|
|
"upFileType"=> "3",
|
|
"outputfiletype"=> "2",
|
|
|
|
|
|
);
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
|
|
|
|
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
|
|
|
|
$result = curl_exec($ch);
|
|
|
|
if(strpos($result, "文件上传成功")!=false )
|
|
{
|
|
|
|
|
|
$rtn= $uploadState="文件上传成功";
|
|
|
|
}
|
|
|
|
return $rtn;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function uploadX2($targetFile, $userId, $companyType, $oprType)
|
|
{
|
|
|
|
|
|
$rtn = new UploadResult();
|
|
|
|
$cookie_file = COOKIEFILE;
|
|
|
|
$uploadMsg = "服务器连接失败";
|
|
$newFileNames = array();
|
|
|
|
|
|
if(!file_exists($cookie_file))
|
|
{
|
|
|
|
//echo "cookie_file is not exists!";
|
|
|
|
$uploadMsg = $targetFile. "用户未授权";
|
|
$rtn->setUploadState($uploadMsg);
|
|
return $rtn;
|
|
}
|
|
|
|
|
|
|
|
if(!file_exists($targetFile)&&!is_dir($dir)){
|
|
|
|
|
|
$uploadMsg = $targetFile. "文件上传失败!文件或目录不存在";
|
|
$rtn->setUploadState($uploadMsg);
|
|
return $rtn;
|
|
}
|
|
|
|
$checkResult = is_dir($targetFile);
|
|
if($checkResult==true){
|
|
|
|
$filesnames = scandir($targetFile);
|
|
foreach ($filesnames as $subfile) {
|
|
|
|
if($subfile!="." && $subfile!="..")
|
|
{
|
|
$subfile=$targetFile."/".$subfile;
|
|
$uploadresult=new UploadResult();
|
|
|
|
$uploadresult = $this->uploadX2($subfile, $userId, $companyType,$oprType);
|
|
if ("文件上传成功"!=$uploadresult->getUploadState()) {
|
|
return $uploadresult;
|
|
}
|
|
|
|
$newFileNames = array_merge((array)$newFileNames, (array)$uploadresult->getNewFileNames());
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
$rtn->setUploadState("文件上传成功");
|
|
$rtn->setNewFileNames($newFileNames);
|
|
return $rtn;
|
|
|
|
}
|
|
|
|
|
|
/////////////////////////////////////////////////////
|
|
|
|
$this->userId=$userId;
|
|
$this->companyType=$companyType;
|
|
|
|
|
|
|
|
if ($oprType == 1) {
|
|
// 上传类型
|
|
$filePath="/待审核的文件/批量DOI查询";
|
|
} else if ($oprType == 2) {
|
|
// 上传类型
|
|
$filePath="/待审核的文件/批量元数据查询";
|
|
} else if ($oprType == 3) {
|
|
// 上传类型
|
|
$filePath="/待审核的文件/追加数据";
|
|
} else if ($oprType == 4) {
|
|
// 上传类型
|
|
$filePath="/待审核的文件/修改数据";
|
|
}
|
|
else
|
|
{
|
|
$filePath="/待审核的文件/追加数据";
|
|
|
|
}
|
|
|
|
|
|
|
|
$post = array(
|
|
"upload"=>"@$targetFile",
|
|
"userId"=>$this->userId,
|
|
"companyType"=>$this->companyType,
|
|
"upFileSpace_s"=>filesize($targetFile) ,
|
|
"clientState"=> true,
|
|
"filePath"=> $filePath,
|
|
"upFileType"=> "3",
|
|
"pageType"=> "clientUpFile",
|
|
|
|
|
|
|
|
);
|
|
$upurl=$this->ip."/chinadoi-manage/manage/doidata-upload.action";
|
|
$ch = curl_init();
|
|
curl_setopt($ch, CURLOPT_URL,$upurl );
|
|
curl_setopt($ch, CURLOPT_HEADER, 1);
|
|
curl_setopt($ch, CURLOPT_VERBOSE, 0);
|
|
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
|
|
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible;)");
|
|
//curl_setopt($ch, CURLOPT_URL, _VIRUS_SCAN_URL);
|
|
curl_setopt($ch, CURLOPT_POST, true);
|
|
|
|
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
|
|
|
|
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
|
|
|
|
$result = curl_exec($ch);
|
|
$header =null;
|
|
if (curl_getinfo($ch, CURLINFO_HTTP_CODE) == '200') {
|
|
$headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
|
|
$header = substr($result, 0, $headerSize);
|
|
|
|
|
|
}
|
|
curl_close($ch);
|
|
|
|
$state=null;
|
|
$newfilename=null;
|
|
|
|
|
|
if(empty($header))
|
|
{
|
|
$uploadMsg = "服务器连接失败";
|
|
}
|
|
else
|
|
{
|
|
$headArr = explode("\n", $header);
|
|
foreach ($headArr as $line) {
|
|
|
|
if(strpos($line, "state") !== false){
|
|
|
|
$tmpary=explode(":",$line);
|
|
$state = trim($tmpary[1]);
|
|
|
|
|
|
}
|
|
|
|
// 获取新文件名
|
|
if(strpos($line, "newFileName") !== false){
|
|
|
|
$tmpary=explode(":",$line);
|
|
$newfilename = trim($tmpary[1]);
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if($state!=null ){
|
|
|
|
|
|
|
|
if($state=="upFile1"){
|
|
$uploadMsg = "文件上传成功";
|
|
} else if($state=="upFile4"){
|
|
|
|
$uploadMsg = $targetFile. "文件上传失败!文件名、目录名或卷标语法不正确";
|
|
} else if($state=="upFile5"){
|
|
$uploadMsg = $targetFile. "文件上传失败!请输入文件名称";
|
|
} else if($state=="upFile6"){
|
|
$uploadMsg = $targetFile. "文件上传失败!您输入的文件名含有非法字符";
|
|
} else if($state=="upFile7"){
|
|
$uploadMsg = $targetFile. "文件上传失败!已有同名文件夹";
|
|
} else if($state=="upFile9"){
|
|
$uploadMsg = $targetFile. "文件上传失败!文件重命名错误请与管理员联系或者重新上传";
|
|
} else if($state=="upFile10"){
|
|
$uploadMsg = $targetFile. "文件上传失败!插入记录有错误请与管理员联系";
|
|
}
|
|
else
|
|
{
|
|
$uploadMsg = $targetFile. "文件上传失败!未知原因";
|
|
}
|
|
|
|
|
|
|
|
$rtn->setNewFileNames($newfilename);
|
|
} else {
|
|
$uploadMsg = "用户没有分配角色!请与管理员联系";
|
|
}
|
|
|
|
}
|
|
|
|
|
|
$rtn->setUploadState($uploadMsg);
|
|
|
|
return $rtn;
|
|
|
|
|
|
}
|
|
|
|
/**
|
|
* DOI注册结果查询
|
|
*
|
|
* @param fileName 系统中的文件名
|
|
* @param userName 用户名
|
|
* @param password 密码
|
|
* @return DOI注册结果类
|
|
*/
|
|
|
|
function getDoiRegResult( $fileName, $userName, $password) {
|
|
|
|
// 初始化返回结果
|
|
$result = null;
|
|
|
|
|
|
$wsdl = DOIQUERYSERVICEURL;
|
|
$client = new SoapClient($wsdl);
|
|
$param = array('in0'=>$fileName,'in1'=>$userName,'in2'=>$password);
|
|
$ret = $client->getDoiRegResult($param);
|
|
if ($ret->out){
|
|
|
|
$result = $ret->out;
|
|
|
|
}
|
|
|
|
|
|
return $result;
|
|
}
|
|
|
|
}
|
|
?>
|