更新图片上传
This commit is contained in:
parent
f647466d4b
commit
eb79169226
|
@ -43,6 +43,28 @@ class UploadController extends BaseAdminController
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//上传图片
|
||||||
|
public function taskImage(): Json
|
||||||
|
{
|
||||||
|
$params=$this->request->post();
|
||||||
|
$result = curl_post_file(env('project.worker_domain').'/middleapi/upload/image', $_FILES['file']['tmp_name'], $_FILES['file']['name'], $_FILES['file']['type'],$this->reqHeader);
|
||||||
|
if($result['code'] == 0){
|
||||||
|
return $this->fail($result['msg']);
|
||||||
|
}
|
||||||
|
return json($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
//上传文件
|
||||||
|
public function taskFile(): Json
|
||||||
|
{
|
||||||
|
$params=$this->request->post();
|
||||||
|
$result = curl_post_file(env('project.worker_domain').'/middleapi/upload/file', $_FILES['file']['tmp_name'], $_FILES['file']['name'], $_FILES['file']['type'],$this->reqHeader);
|
||||||
|
if($result['code'] == 0){
|
||||||
|
return $this->fail($result['msg']);
|
||||||
|
}
|
||||||
|
return json($result);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @notes 上传视频
|
* @notes 上传视频
|
||||||
* @return Json
|
* @return Json
|
||||||
|
|
|
@ -346,6 +346,25 @@ function curl_post($url,$data,$headers=[]) {
|
||||||
return json_decode($output,true);
|
return json_decode($output,true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function curl_post_file($url, $filePath, $fieldName, $fieldExt, $headers=[]) {
|
||||||
|
//初始化curl
|
||||||
|
$ch = curl_init($url);
|
||||||
|
$cfile = curl_file_create($filePath, $fieldExt, $fieldName);
|
||||||
|
// 设置 POST 数据
|
||||||
|
$data = array('file' => $cfile);
|
||||||
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||||
|
curl_setopt($ch, CURLOPT_POST,1);
|
||||||
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
|
||||||
|
curl_setopt($ch, CURLOPT_HEADER, 0);
|
||||||
|
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120);
|
||||||
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
|
||||||
|
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
|
||||||
|
|
||||||
|
$output = curl_exec($ch);
|
||||||
|
curl_close($ch);
|
||||||
|
return json_decode($output,true);
|
||||||
|
}
|
||||||
|
|
||||||
function curl_get($url){
|
function curl_get($url){
|
||||||
$ch = curl_init();
|
$ch = curl_init();
|
||||||
curl_setopt($ch, CURLOPT_URL, $url);
|
curl_setopt($ch, CURLOPT_URL, $url);
|
||||||
|
|
Loading…
Reference in New Issue