设置网页地址

将下面这个网页文件,上传到自己的网站空间中,并在“api接口”页面,将“网页地址”设置成这个文件的URL地址。
那么,以后在后台上传图片或者通过API接口上传图片时,生成的图片地址,就是通过自己的网站域名访问。

……
点击下载网页文件
……
文件代码:

<?php
error_reporting(E_ERROR | E_WARNING | E_PARSE);

$domain = $_SERVER['SERVER_NAME'];

function getIp()
{
	if(!empty($_SERVER["HTTP_X_FORWARDED_FOR"]))
	{
		$cip = $_SERVER["HTTP_X_FORWARDED_FOR"];
	}
	else if(!empty($_SERVER["REMOTE_ADDR"]))
	{
		$cip = $_SERVER["REMOTE_ADDR"];
	}
	else
	{
		$cip = '';
	}
	preg_match("/[\d\.]{7,15}/", $cip, $cips);
	$cip = isset($cips[0]) ? $cips[0] : 'unknown';
	unset($cips);

	return $cip;
}

function analysis( $fuhao , $buffer)
{
	$pos = strpos($buffer, $fuhao);
	$pos1 = strpos($buffer, "\r\n", $pos );
	return substr($buffer, $pos + strlen($fuhao), $pos1 - $pos - strlen($fuhao));
}

	$p = $_REQUEST['8tp'];
	if ( $p == NULL )
	{
		die ("HTTP 404 - File not found");
	}

	$p = strtolower($p);
	
	$pos = strpos($p, ".");
	$url = "http://" . substr($p, 0, $pos) . ".8tupian.com/" . substr($p, $pos + 1);

	$ip = getIp();
	
      $headers = array(
	  "Accept: ".$_SERVER['HTTP_ACCEPT'],
	  "User-Agent: ". $_SERVER['HTTP_USER_AGENT'],
	  "referer: ". $_SERVER['HTTP_REFERER'],
	  "Cookie: ". $_SERVER['HTTP_COOKIE'],
	  "X-Forwarded-For: " . $ip,
	  "Authorization: ". $domain,
      );

    $curl = curl_init();
	
    curl_setopt($curl, CURLOPT_URL, $url );
	
    curl_setopt($curl, CURLOPT_HEADER, true);
	
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

    curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
	
    $data = curl_exec($curl);
	
	$headerSize = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
	$header = substr($data, 0, $headerSize);
	
    curl_close($curl);
	
	$contenttype = analysis("Content-Type: ", $header);
	$setcookie = analysis("Set-Cookie: ", $header);
	
	header("Content-Type: " . $contenttype);
	header("Set-Cookie: " . str_replace("8tupian.com", $domain, $setcookie) );

	echo substr($data, $headerSize  );;
?>

……

设置方法: