<?php
include_once("inc/conn.php");
include_once("inc/utility_all.php");
include_once("inc/utility_org.php");
include_once("inc/utility_file.php");
function http_request($url, $data = null)
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
if (!empty($data)) {
// curl_setopt($curl, CURLOPT_HTTPHEADER, [
// 'Content-Type: application/post',
// ]);
// curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
}
curl_setopt($curl, CURLOPT_USERAGENT, 'PostmanRuntime/7.29.0');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
$output = curl_exec($curl);
curl_close($curl);
return $output;
}
function convertEncoding($string){
$encode = stristr(PHP_OS, 'WIN') ? 'GBK' : 'UTF-8';
$string = iconv('UTF-8', $encode, $string);
return $string;
}
$sql="select b.data_m882,b.data_m882_key,b.data_m883_key,b.data_m883,a.begin_time,a.run_id,a.data_m6316 from bpm_data_36 as a,bpm_data_36_child as b where a.run_id=b.run_id and (a.data_m6316 is null or a.data_m6316='') and a.id>0 and a.id<=8500 ";
$rows =TD::DB()->prepareQuery($sql);
if(is_array($rows) && !empty($rows))
{
foreach($rows as $v){
$zhengwen=explode('*',$v['data_m882']);
$zhengwen_key=explode(',',$v['data_m882_key']);
$zhengwen_shu = sizeof($zhengwen_key);
$path = str_replace('-','',$v['begin_time']);
$path = substr($path , 0 , 8);
$run_id = $v['run_id'];
$time = date("Y-m-d");
for($i=1; $i<$zhengwen_shu ; $i++){
$yueri = explode('_',$zhengwen_key[$i-1]);
$zhengwen_yueri = substr($yueri[0],-4);
$zhengwen_suiji = $yueri[1];
$file_fullpath = '/opt/tdoa/attach/approve_center/'.$zhengwen_yueri.'/'. $zhengwen_suiji.'.'.$zhengwen[$i-1];
$file_url = new \CURLFile(convertEncoding($file_fullpath));
$postData = [
"file"=>$file_url,
"path"=>'/'.$path.'/',
"filename"=>$zhengwen[$i-1],
"type"=>'fw'
];
$url = 'http://192.200.0.63:61160/receiveFiles';
$res = http_request($url,$postData);
$msg = json_decode($res,true);
if($msg['msg'] = 'success' and $msg['code'] = '200'){
$sql2="UPDATE bpm_data_49 SET data_m6315='1' WHERE run_id=$run_id";
TD::DB()->prepareQuery($sql2);
file_put_contents("/opt/tdoa/webroot/ftp/sites.txt",$time.' | '.$run_id." 正文上传成功\r\n", FILE_APPEND);
}else{
file_put_contents("/opt/tdoa/webroot/ftp/sites.txt",$time.' | '.$run_id." 正文上传失败\r\n", FILE_APPEND);
}
}
$fujian=explode('*',$v['data_m883']);
$fujian_key=explode(',',$v['data_m883_key']);
$fujian_shu = sizeof($fujian_key);
for($i=1; $i<$fujian_shu ; $i++){
$yueri = explode('_',$fujian_key[$i-1]);
$fujian_yueri = substr($yueri[0],-4);
$fujian_suiji = $yueri[1];
$file_fullpath = '/opt/tdoa/attach/approve_center/'.$fujian_yueri.'/'. $fujian_suiji.'.'.$fujian[$i-1];
$file_url = new \CURLFile(convertEncoding($file_fullpath));
$postData = [
"file"=>$file_url,
"path"=>'/'.$path.'/',
"filename"=>$fujian[$i-1],
"type"=>'fw'
];
$url = 'http://192.200.0.63:61160/receiveFiles';
$res = http_request($url,$postData);
$msg = json_decode($res,true);
if($msg['msg'] = 'success' and $msg['code'] = '200'){
$sql2="UPDATE bpm_data_49 SET data_m6315='2' WHERE run_id=$run_id";
TD::DB()->prepareQuery($sql2);
file_put_contents("/opt/tdoa/webroot/ftp/sites2.txt",$time.' | '.$run_id." 附件上传成功\r\n", FILE_APPEND);
}else{
file_put_contents("/opt/tdoa/webroot/ftp/sites2.txt",$time.' | '.$run_id." 附件上传失败\r\n", FILE_APPEND);
}
}
}
}
echo ok;
//var_dump($res);die;
php http curl 上传附件
最新推荐文章于 2023-09-06 09:43:20 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)