京东图床上传接口 PHP源码

 5593

站长在制作网站的时候,前期往往投入都有限,而图片有事比较占用服务器空间的,所以都会选择使用图床,但是哪里的图床最稳定呢。

新浪?京东?淘宝?百度?搜狗还是360

不过一般来说,还是京东、淘宝的比较稳定!

闲话不多说,直接上代码:

  1. <?php
  2. /*
  3. *    京东图床PHP代码
  4. */
  5. if (class_exists('CURLFile')) { // php 5.5
  6.     $post['file'] = new \CURLFile(realpath($_FILES['Filedata']['tmp_name']));
  7. } else {
  8.     $post['file'] = '@'.realpath($_FILES['Filedata']['tmp_name']);
  9. }
  10. $rel = get_curl('https://search.jd.com/image?op=upload',$post);
  11. preg_match('/callback(?:\(\")(.*)(?:\"\))/i',$rel,$matches);
  12. if (!$matches[1]) {
  13.     exit('图片上传失败!');
  14. }
  15. $arr = array(
  16.     'code'    => 200,
  17.     'imgurl'  => 'https://img'.rand(10,14).'.360buyimg.com/uba/'.$matches[1]
  18. );
  19. exit(json_encode($arr));
  20. function get_curl($url, $post=0, $referer=0, $cookie=0, $header=0, $ua=0, $nobaody=0){
  21.     $ch = curl_init();
  22.     curl_setopt($ch, CURLOPT_URL, $url);
  23.     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  24.     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  25.     $httpheader[] = "Accept:application/json";
  26.     $httpheader[] = "Accept-Encoding:gzip,deflate,sdch";
  27.     $httpheader[] = "Accept-Language:zh-CN,zh;q=0.8";
  28.     $httpheader[] = "Connection:close";
  29.     curl_setopt($ch, CURLOPT_HTTPHEADER, $httpheader);
  30.     if ($post) {
  31.         curl_setopt($ch, CURLOPT_POST, 1);
  32.         curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
  33.     }
  34.     if ($header) {
  35.         curl_setopt($ch, CURLOPT_HEADER, true);
  36.     }
  37.     if ($cookie) {
  38.         curl_setopt($ch, CURLOPT_COOKIE, $cookie);
  39.     }
  40.     if($referer){
  41.         if($referer==1){
  42.             curl_setopt($ch, CURLOPT_REFERER, 'http://m.qzone.com/infocenter?g_f=');
  43.         }else{
  44.             curl_setopt($ch, CURLOPT_REFERER, $referer);
  45.         }
  46.     }
  47.     if ($ua) {
  48.         curl_setopt($ch, CURLOPT_USERAGENT, $ua);
  49.     }
  50.     else {
  51.         curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Linux; U; Android 4.0.4; es-mx; HTC_One_X Build/IMM76D) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0");
  52.     }
  53.     if ($nobaody) {
  54.         curl_setopt($ch, CURLOPT_NOBODY, 1);
  55.     }
  56.     curl_setopt($ch, CURLOPT_TIMEOUT, 3);
  57.     curl_setopt($ch, CURLOPT_ENCODING, "gzip");
  58.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  59.     $ret = curl_exec($ch);
  60.     curl_close($ch);
  61.     return $ret;
  62. }


本文网址:https://www.zztuku.com/detail-7670.html
站长图库 - 京东图床上传接口 PHP源码
申明:如有侵犯,请 联系我们 删除。

评论(0)条

您还没有登录,请 登录 后发表评论!

提示:请勿发布广告垃圾评论,否则封号处理!!

    编辑推荐