• 2022-09-04被罚款200元记6分.
  • 特么的.电脑风扇坏了.快递还全部停发.太难了...求求了.疫情赶紧走吧.
  • 难啊难!要钱难!
  • 更新到WordPress5.6啦
  • 有点伤心了,今年净遇到王某海这种人.
  • 难啊难...
  • 七牛的JS SDK 的文档真坑啊.
  • 蓝奏云分享部分地区无法访问需手动修改www.lanzous.com变为:www.lanzoux.com
  • 好气啊~原来使用的CDN服务商莫名其妙的给我服务取消了~
  • 遇见一个沙雕汽车人.

京东图床上传接口 PHP源码

PHP KIENG 5年前 (2019-01-23) 193398次浏览 已收录 1个吐槽 扫描二维码

哪里的图床最稳定呢。

新浪,京东,淘宝,百度,搜狗。360

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

下面是京东图床PHP 上传代码

<?php
/*
*	京东图床 PHP 代码
*	KIENG 博客
*	http://blog.kieng.cn
*/

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;
}

KIENG.CN , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA 4.0协议进行授权
转载请注明出处:京东图床上传接口 PHP 源码
本文章链接:https://blog.kieng.cn/449.html
喜欢 (6)
KIENG
关于作者:
一个热衷网络的Man
发表我的评论
取消评论
表情 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 快速获取昵称
  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
(1)个小伙伴在吐槽
  1. 京東的接口失效了,請問能否告知京東和QQ的新接口?
    SCV | 中国河北廊坊市 联通2021-03-01 20:14 回复 Windows 10 | Firefox浏览器 56.0