新聞中心
最近在寫一個關(guān)于php發(fā)送日志的功能,需要一個后臺上傳的功能,需要用curl進(jìn)行發(fā)送post請求,但是網(wǎng)絡(luò)上面找了一些文章,經(jīng)過測試卻沒有任何反應(yīng),以下是我經(jīng)過實際測試通過的上傳代碼:
創(chuàng)新互聯(lián)專注于江門網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗。 熱誠為您提供江門營銷型網(wǎng)站建設(shè),江門網(wǎng)站制作、江門網(wǎng)頁設(shè)計、江門網(wǎng)站官網(wǎng)定制、小程序制作服務(wù),打造江門網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供江門網(wǎng)站排名全網(wǎng)營銷落地服務(wù)。
/**
* 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://fisionsoft.com.cn/article/jgjgid.html