《PHP編程:PHP實(shí)現(xiàn)微信圖片上傳到服務(wù)器的方法示例》要點(diǎn):
本文介紹了PHP編程:PHP實(shí)現(xiàn)微信圖片上傳到服務(wù)器的方法示例,希望對您有用。如果有疑問,可以聯(lián)系我們。
PHP實(shí)戰(zhàn)本文實(shí)例講述了PHP實(shí)現(xiàn)微信圖片上傳到服務(wù)器的方法.分享給大家供大家參考,具體如下:
PHP實(shí)戰(zhàn)
$pic_img=trim( $postObj->PicUrl);
if($type=="image"){
$pic_url=save_file_to_sever($pic_img,$fromUsername);
}
GetRootPath(){
$sRealPath = realpath('./');
$sSelfPath = $_SERVER['PHP_SELF'];
$sSelfPath = substr($sSelfPath, 0, strrpos($sSelfPath, '/'));
return substr($sRealPath, 0, strlen($sRealPath) - strlen($sSelfPath));
}
function save_file_to_sever($url,$fromid){
$gen=GetRootPath();
$time=time();
$newfname =$gen."/weixin/wx_huodong/xiawucha/".$fromid.$time.'.jpg';
$ch=curl_init();
$timeout=5;
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
$img=curl_exec($ch);
curl_close($ch);
$size=strlen($img);
//文件大小
$fp2=@fopen($newfname,'a');
fwrite($fp2,$img);
fclose($fp2);
return "http://www.xxx.com/weixin/wx_huodong/xiawucha/".$fromid.$time.'.jpg';
}
PHP實(shí)戰(zhàn)更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《PHP微信開發(fā)技巧匯總》、《PHP編碼與轉(zhuǎn)碼操作技巧匯總》、《PHP網(wǎng)絡(luò)編程技巧總結(jié)》、《PHP基本語法入門教程》、《php字符串(string)用法總結(jié)》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總》
PHP實(shí)戰(zhàn)希望本文所述對大家PHP程序設(shè)計(jì)有所幫助.
轉(zhuǎn)載請注明本頁網(wǎng)址:
http://www.snjht.com/jiaocheng/556.html