0
点赞
收藏
分享

微信扫一扫

phpcurl上传文件

alanwhy 2023-02-16 阅读 72


$file = realpath('gif/1.gif'); //要上传的文件
$fields['f'] = '@'.$file;

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://localhost/ajax_server.php?id=1");
curl_setopt($ch, CURLOPT_POST, 1 );
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);

curl_exec ($ch);
curl_close ($ch);

php5.6后​​@​​​不能用了需要​​CURLFile​​这个函数,下面就是

<?php

$url = "https://api.yunhetong.com/api/template/upload";

$file = realpath("./技术咨询服务合同.docx"); //要上传的文件

$post_data = [
"templateName" => "技术咨询服务合同测试",
"multipartFile" =>new CURLFile($file)
];

$ch = curl_init();
curl_setopt($ch , CURLOPT_URL , $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,CURLOPT_HTTPHEADER,["token:"."eyJhbGciOiJIUzUxMiJ9.eyJqdGkiOiJWN1ZqRUNOOElEd2dJVXNNQWxCUTZka2lORk9oRkhkdU44a3J2UEpOUGNZPSIsImV4cCI6MTYyMzIzMDMwM30.yoCVn3oxoRsr0YyjRVBlyZosKRIdpaChSJwNLegpN1ACx4bgvcR3YjJ08zUzeu_a7xsfXLQ5Zh7icTENxka-ng"]);
curl_setopt($ch , CURLOPT_POSTFIELDS, $post_data);
$output = curl_exec($ch);
curl_close($ch);
echo $output;
die;
?>


举报

相关推荐

0 条评论