当前位置:首页 » 好文分享 » 详情

    京东图床上传接口PHP源码

    京东图床上传接口PHP源码:
    <?php
    /*
    *京东图床PHP代码
    */
    if (class_exists('CURLFile')) { // php 5.5
    	$post['file'] = new \CURLFile(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));
    function get_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; Android 4.0.4; es-mx; HTC_One_X Build/IMM76D) AppleWebKit/534.30 (KHTML, like Gecko) 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;
    }

    打赏
    X
    打赏方式:
    • 支付宝
    • 微信
    • QQ红包

    打开支付宝扫一扫
    日期:2019年02月23日 13:16:43 星期六   分类:好文分享   浏览(42828)
    本文地址:https://www.blogs.hk/post-4192.html   [百度已收录]
    声明:本页信息由网友自行发布或来源于网络,真实性、合法性由发布人负责,请仔细甄别!本站只为传递信息,我们不做任何双方证明,也不承担任何法律责任。文章内容若侵犯你的权益,请联系本站删除!
    版权所有:《博客之家
    文章标题:《京东图床上传接口PHP源码
    除非注明,文章均为 《博客之家》 原创
    转载请注明本文短网址:https://www.blogs.hk/post-4192.html  [生成短网址]

    留言咨询

    自动获取QQ

    昵称

    邮箱

    网址

        站点统计

        • 收录网址:3370 个
        • 发布文章:3008 条
        • 在线人数:1人
        • 总访问量:269816991次
        • 本站运行:12年4月25天
        Copyright © 2025 博客之家 版权所有  
        關於本站免責聲明sitemap新站登錄