phpcurlpost上传文件

最近在写一个关于php发送日志的功能,需要一个后台上传的功能,需要用curl进行发送post请求,但是网络上面找了一些文章,经过测试却没有任何反应,以下是我经过实际测试通过的上传代码:

创新互联专注于江门网站建设服务及定制,我们拥有丰富的企业做网站经验。 热诚为您提供江门营销型网站建设,江门网站制作、江门网页设计、江门网站官网定制、小程序制作服务,打造江门网络公司原创品牌,更为您提供江门网站排名全网营销落地服务。

/**

*  curl文件上传

*  @var  struing  $r_file  上传文件的路劲和文件名

*/

function upload_file($r_file)

{

/*$fields['uploadfile'] = "@".realpath($r_file);*/

    $varname = 'uploadfile';

$name = $r_file;

$type = 'text/plain';

$key = "$varname\"; filename=\"$name\r\nContent-Type: $type\r\nAccept: \"";

$fields[$key] = file_get_contents($r_file);

$curl = curl_init();

curl_setopt($curl, CURLOPT_URL,REMOTE_HOST.'/source/uploadLog.php');

curl_setopt($curl,CURLOPT_POST,1);

curl_setopt($curl,CURLOPT_POSTFIELDS,$fields);

curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($curl, CURLOPT_HEADER, 0);

$result = curl_exec($curl);  //$result 获取页面信息

curl_close($curl);

echo $result;

$json_data = json_decode($result,true);

if($json_data["status"] == 1)

{

return true;

}

return false;

}


当前标题:phpcurlpost上传文件
文章路径:http://pwwzsj.com/article/jgjgid.html