简介站长在制作网站的时候,前期往往投入都有限,而图片有事比较占用服务器空间的,所以都会选择使用图床,但是哪里的图床最稳定呢。新浪?京东?淘宝?百度?搜狗还是360不过一般来说,还是京东、淘宝的比较稳定!闲话不多说,直接上代码:
站长在制作网站的时候,前期往往投入都有限,而图片有事比较占用服务器空间的,所以都会选择使用图床,但是哪里的图床最稳定呢。
新浪?京东?淘宝?百度?搜狗还是360
不过一般来说,还是京东、淘宝的比较稳定!
闲话不多说,直接上代码:
<?php/**京东图床PHP代码*/if(class_exists('CURLFile')){//php5.5$post['file']=newCURLFile(realpath($_FILES['Filedata']['tmp_name']));}else{$post['file']='@'.realpath($_FILES['Filedata']['tmp_name']);}$rel=get_curl('https://search.jd.com/image?op=upload',$post);preg_match('/callback(?:(")(.*)(?:"))/i',$rel,$matches);if(!$matches[1]){exit('图片上传失败!');}$arr=array('code'=>200,'imgurl'=>'https://img'.rand(10,14).'.360buyimg.com/uba/'.$matches[1]);exit(json_encode($arr));functionget_curl($url,$post=0,$referer=0,$cookie=0,$header=0,$ua=0,$nobaody=0){$ch=curl_init();curl_setopt($ch,CURLOPT_URL,$url);curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,false);$httpheader[]="Accept:application/json";$httpheader[]="Accept-Encoding:gzip,deflate,sdch";$httpheader[]="Accept-Language:zh-CN,zh;q=0.8";$httpheader[]="Connection:close";curl_setopt($ch,CURLOPT_HTTPHEADER,$httpheader);if($post){curl_setopt($ch,CURLOPT_POST,1);curl_setopt($ch,CURLOPT_POSTFIELDS,$post);}if($header){curl_setopt($ch,CURLOPT_HEADER,true);}if($cookie){curl_setopt($ch,CURLOPT_COOKIE,$cookie);}if($referer){if($referer==1){curl_setopt($ch,CURLOPT_REFERER,'http://m.qzone.com/infocenter?g_f=');}else{curl_setopt($ch,CURLOPT_REFERER,$referer);}}if($ua){curl_setopt($ch,CURLOPT_USERAGENT,$ua);}else{curl_setopt($ch,CURLOPT_USERAGENT,"Mozilla/5.0(Linux;U;Android4.0.4;es-mx;HTC_One_XBuild/IMM76D)AppleWebKit/534.30(KHTML,likeGecko)Version/4.0");}if($nobaody){curl_setopt($ch,CURLOPT_NOBODY,1);}curl_setopt($ch,CURLOPT_TIMEOUT,3);curl_setopt($ch,CURLOPT_ENCODING,"gzip");curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);$ret=curl_exec($ch);curl_close($ch);return$ret;}