京东免费图床上传接口代码PHP源码

  • 内容
  • 相关

要论哪里的图床最稳定,就一定要说到目前主流的新浪,京东,淘宝,百度,搜狗,360图床了。

不过一般来说 还是京东,淘宝的比较稳定!稳定就是代表你的图片上传后不会被删除也不会出现打不开404等情况。

下面附上京东图床PHP上传代码供大家学习参考。

<?php
/*
*	京东图床PHP代码
*	大幕博客
*	www.52damu.com
*/

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);
	$httpssheader[] = "Accept:application/json";
	$httpssheader[] = "Accept-Encoding:gzip,deflate,sdch";
	$httpssheader[] = "Accept-Language:zh-CN,zh;q=0.8";
	$httpssheader[] = "Connection:close";
	curl_setopt($ch, CURLOPT_HTTPHEADER, $httpssheader);
	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, 'httpss://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;
}

本文标签:

版权说明:若无特殊注明,均为【大幕博客】原创,转载请保留文章出处

本文链接:京东免费图床上传接口代码PHP源码 - https://blog.52damu.com/wangyedaima/2665.html

发表评论

电子邮件地址不会被公开。 必填项已用*标注

允许邮件通知