?php
header('content-type:text/html;charset=gb2312');
//要注意你需要上傳的網(wǎng)站服務(wù)器的運(yùn)行環(huán)境,還要看它的請(qǐng)求是否被壓縮和轉(zhuǎn)碼還有就是
//在框架中或者說(shuō)php5.3以下的版本可以用@,但是其它的就只能用new CURLfile()函數(shù)來(lái)轉(zhuǎn)化文件了
//注意你要發(fā)送的服務(wù)器的header頭的結(jié)構(gòu)和特殊參數(shù),實(shí)在不行就自己構(gòu)建一個(gè)。廢話不多說(shuō),直接上代碼。
function curl_form($post_data,$sumbit_url,$http_url,$cookie_file){
$headers = array();
$headers[] = 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8';
$headers[] = 'Cache-Control: max-age=0';
$headers[] = 'Accept-Encoding: gzip, deflate';
$headers[] = 'Origin: http://my.***.com';
$headers[] = 'Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3';
$headers[] = 'Upgrade-Insecure-Requests: 1';
$headers[] = 'Content-Type: application/x-www-form-urlencoded';
$headers[] = 'User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:28.0) Gecko/20100101 Firefox/28.0';
$headers[] = 'Connection: keep-alive';
// $headers[] = 'Cookie: ASPSESSIONIDCCTCTQQC=KBGLPDKBIKDIDCBGFOKNMKOE';
//初始化
$ch = curl_init();
//設(shè)置變量
curl_setopt($ch, CURLOPT_URL, $sumbit_url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//執(zhí)行結(jié)果是否被返回,0是返回,1是不返回
curl_setopt($ch, CURLOPT_HEADER, 0);//參數(shù)設(shè)置,是否顯示頭部信息,1為顯示,0為不顯示
curl_setopt($ch, CURLOPT_REFERER, $http_url);
//表單數(shù)據(jù),是正規(guī)的表單設(shè)置值為非0
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch,CURLOPT_PROXY,'127.0.0.1:8888');
// curl_setopt($ch, CURLOPT_ENCODING, "");
// curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post_data));
//執(zhí)行并獲取結(jié)果
$output = curl_exec($ch);
if($output === FALSE)
{
echo "br/>","cUrl Error:".curl_error($ch);
}else{
return $output;
}
// 釋放cURL句柄
curl_close($ch);
}
$temp = array();
$temp['title'] = iconv( "utf-8", "gb2312//IGNORE" , "牛排店加盟");
$temp['ly'] = iconv( "utf-8", "gb2312//IGNORE" , "特色餐飲加盟");
$temp['classid'] = iconv( "utf-8", "gb2312//IGNORE" , "7159");
$temp['newssort'] = iconv( "utf-8", "gb2312//IGNORE" , "1");
$temp['panduan'] = iconv( "utf-8", "gb2312//IGNORE" , "0");
$temp['submit_button'] = iconv( "utf-8", "gb2312//IGNORE" , "發(fā)布");
$temp['addr'] = iconv( "utf-8", "gb2312//IGNORE" , "bjcanyin");
$temp['ContentBg'] = "";
$temp['newss'] = iconv( "utf-8", "gb2312//IGNORE" , htmlspecialchars_decode("p>阿會(huì)計(jì)師的賀卡收到框架/p>p>img alt=\"\"
src=\" http://localhost/super/Uploads/img/2017-08-10/598c145a9527e.jpg\" style=\"height:243px; width:324px\" />/p>", ENT_QUOTES));
$cookie_file = dirname(__FILE__)."/jdzj.tmp";
$sumbit_url = "http://***/news/***.asp";
$http_url="http://***/news/***.asp?act=addok";
$img = curl_form($temp,$http_url,$sumbit_url,$cookie_file);
var_dump($img);
PS:關(guān)于PHP curl選項(xiàng)詳細(xì)說(shuō)明可參考https://www.jb51.net/article/39331.htm
更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《php curl用法總結(jié)》、《PHP網(wǎng)絡(luò)編程技巧總結(jié)》、《PHP數(shù)組(Array)操作技巧大全》、《php字符串(string)用法總結(jié)》、《PHP數(shù)據(jù)結(jié)構(gòu)與算法教程》及《PHP中json格式數(shù)據(jù)操作技巧匯總》